Several bug fixes

Closes #41
Closes #42
Closes #44