Lots of improvements to unit tests.  A few bug fixes.