add tests, fix bugs.