Reworks script into function

Adjusts the script to use functions, still need to work into one master
function to call.