refactoring & bugfixes