Enhance error handling