refactoring according to jonas comments