add tests and bugfixes