bugfixes, added test function