Improved error reporting and handling