Bugfixes and test