Fix NameError for missing 'record' variable.