add some tests and fix bugs