Fixed the error handling.