Improved global error handling