Bugfix and refactoring
Minor bugfix
Refactoring