add more tests; fix more bugs