Fixed some bugs
Fixes #19 as well as #21