def _correct_record(record):
errors = []<EOL>for tag in list(record.keys()):<EOL><INDENT>upper_bound = '<STR_LIT>'<EOL>n = len(tag)<EOL>if n > <NUM_LIT:3>:<EOL><INDENT>i = n - <NUM_LIT:3><EOL>while i > <NUM_LIT:0>:<EOL><INDENT>upper_bound = '<STR_LIT>' % ('<STR_LIT:0>', upper_bound)<EOL>i -= <NUM_LIT:1><EOL><DEDENT><DEDENT>if tag == '<STR_LIT:!>':<EOL><INDENT>errors.append((<NUM_LIT:1>, '<STR_LIT>' +<EOL>str([f[<NUM_LIT:4>] for f in record[tag]]) + '<STR_LIT:)>'))<EOL>record['<STR_LIT>'] = record.pop(tag)<EOL>tag = '<STR_LIT>'<EOL><DEDENT>elif not ('<STR_LIT>' <= tag <= upper_bound or<EOL>tag in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>errors.append(<NUM_LIT:2>)<EOL>record['<STR_LIT>'] = record.pop(tag)<EOL>tag = '<STR_LIT>'<EOL><DEDENT>fields = []<EOL>for field in record[tag]:<EOL><INDENT>if field[<NUM_LIT:0>] == [] and field[<NUM_LIT:3>] == '<STR_LIT>':<EOL><INDENT>errors.append((<NUM_LIT:8>, '<STR_LIT>' + str(field[<NUM_LIT:4>]) + '<STR_LIT:)>'))<EOL><DEDENT>subfields = []<EOL>for subfield in field[<NUM_LIT:0>]:<EOL><INDENT>if subfield[<NUM_LIT:0>] == '<STR_LIT:!>':<EOL><INDENT>errors.append((<NUM_LIT:3>, '<STR_LIT>' + str(field[<NUM_LIT:4>]) + '<STR_LIT:)>'))<EOL>newsub = ('<STR_LIT>', subfield[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>newsub = subfield<EOL><DEDENT>subfields.append(newsub)<EOL><DEDENT>if field[<NUM_LIT:1>] == '<STR_LIT:!>':<EOL><INDENT>errors.append((<NUM_LIT:4>, '<STR_LIT>' + str(field[<NUM_LIT:4>]) + '<STR_LIT:)>'))<EOL>ind1 = "<STR_LIT:U+0020>"<EOL><DEDENT>else:<EOL><INDENT>ind1 = field[<NUM_LIT:1>]<EOL><DEDENT>if field[<NUM_LIT:2>] == '<STR_LIT:!>':<EOL><INDENT>errors.append((<NUM_LIT:5>, '<STR_LIT>' + str(field[<NUM_LIT:4>]) + '<STR_LIT:)>'))<EOL>ind2 = "<STR_LIT:U+0020>"<EOL><DEDENT>else:<EOL><INDENT>ind2 = field[<NUM_LIT:2>]<EOL><DEDENT>fields.append((subfields, ind1, ind2, field[<NUM_LIT:3>], field[<NUM_LIT:4>]))<EOL><DEDENT>record[tag] = fields<EOL><DEDENT>return errors<EOL>
Check and correct the structure of the record.

:param record: the record data structure
:return: a list of errors found