Improved error message handling