unit tests and related fixes