unit test and bug fix