fix some bugs, add test