Refactor

See the commits for complete changelog.

I've refactored it quite a bit, but it could easily be extended this way.

Closes #36.