Cleanup & bug fix

Fixes #279.