Minor improvement to error handling