Updated the error handling.