tried to separate into functions. failed. they need to be defined before they're called :/ need to find an easier way to separate out the code properly.