Better unit test coverage. Fixed a couple bugs in the process.