fix bug and add test case