Fix the error handling