Refactoring. Pull some code out into separate methods