finish unit test and bug fix