refactoring out some code into its own method