unit test and final fixes