add tests and bugfix