Slight improvement to error handling.