fixed some bugs, including (but not limited to) #112.