More refined error handling