lots of unittests and fixes for various things.