Turn the script into a function