bugfixes and more tests