refactoring to make code easier to follow