Unit test new functionality and fix a few bugs