refactor script: subroutines