Bug fixes

Fixes #60 and #173.