refactored to subroutines