Developed some unit tests. Fixed some problems exposed by the new unit test.