abstracted the four functions into a single function. a lot of duplicate code that i want to rework before i start testing