add more tests and fix more bugs