split a bunch of things out into their own functions, as it should have been from the beginning