refactoring bugfixes