add tests and fix