remove un-needed classes from the script
store the last error for closer inspection
minor cleanup to make the code more readable