Fix some bugs. Fixes #31