unit tests and fixes