unit test and more fixes