refactoring; bugfixing