broke work into subroutines and cleaned up output