Improved error handling and passing of error messages