Minor improvements to error handling.