error handling improvement