bugfixes, added test code.