Bugfixes and more tests