bugfix + refactor