add tests and fixes