refactoring to make code easier to explain