refactor some code into a subroutine