Added error reporting to the script