Fixes

this PR fixes bugs. please see the commit messages.

Fixes #270, #325.