refactor subroutine