fix bug and add new test cases