Fix #35 and some other bugs