Fix up tests

* added tests for functionality that wasn't tested according to
  coverage
* fixed some bugs I found along the way
* tweaked some tests for better maintainability