Tests, bugfixes