this branch is way too complex to go in the main file. this should be split out