Started work on some unit tests and fixed some minor bugs that the unit tests highlighted. More code coverage to come.