more improvements to error handling