Bugfix and Refactoring