minor improvements to error handling