unittests and bug fixes