added comments and a little error check for the script execution