Bug fixes and improved unit tests, more unit test refinement to come.