add tests and fix some mistakes