working on splitting off parts of the way too long loop into other functions. need to iron out one of them still