refactoring in tests and bugfixing