refactoring according to Alexander's comments