prepare for pr by cleaning up code per issues with previous pr
    -broke out functions previously nested in handleStream
    -removed absurd globals
    -cleaned up some redundancy