Bug fixes

Fixes #610 and #600.