Clean-up the script and add comments