Corrected the error handling to be more consistent.