more bugfixes and test code