refinement of error handling