test cases and bug fix