add test, fix some bugs