def _clean_headers(fits_header):
    """
    Hopefully not Gemini specific.
    Remove invalid cards and add missing END cards after extensions.
    :param fits_header: fits_header a string of keyword/value pairs
    """
    new_header = []
    for line in fits_header.split('\n'):
        if len(line.strip()) == 0:
            pass
        elif line.startswith('--- HDU 0'):
            pass
        elif line.startswith('--- HDU'):
            new_header.append('END\n')
        elif line.strip() == 'END':
            new_header.append('END\n')
        elif '=' not in line:
            pass
        else:
            new_header.append('{}\n'.format(line))
    new_header.append('END\n')
    return ''.join(new_header)
