unit test and fix some errors