refactored the entire setup stuff into a bunch of functions