add unit test and fix some bug