minor bug fixes and more unit tests.