Functions created

Function definitions completed and comments added throughout the script.