Refactor bugfix