fix some bugs, add test case