add some tests, fix some bugs