add test and bugfixes