Various bug fixes (see description)

Fixes #35
Fixes #34
Fixes #33