Updated the error handling