add tests and debug