fixes, and a bunch of new unit tests.