Fixed bug #3 and some other bugs