Enhanced error handling