add a proper test suite, fix some bugs