Fixed #21 and some other minor bugs