Fixed several bugs, including #55 and the crash from #58