finish unit tests and fix bugs