Moar tests

Much better test coverage, and a bunch of miscellaneous refactoring that got swept up in making the tests pretty.

Closes #20