Bugfixing, refactoring