refactoring and simplifying