improvements to error handling