Fixed #152
Fixed various other bugs