Fix bug and update test cases