unit test and code fixes