Fixes to unittests and cleanup