refine error handling