unit test and some corrections