add tests and fix issues