move all functionality into subroutines