Add more error handling to the script