Refined error handling