Refactor

See the commits for complete changelog.

Closes #37.