corrected the error handling