bug fixes and a simple unit test.