Bugfix & refactoring