Some bugfixes and more tests