fix bug, add test cases