def METHOD_NAME(f1):
    # remove first, then add back consistently
    lines = f1.strip().splitlines()
    # need to avoid removing if they are indented:
    if lines[-2].startswith('win.close()') or lines[-2].startswith('core.quit()'):
        lines[-2] = ''
    if lines[-1].startswith('win.close()') or lines[-1].startswith('core.quit()'):
        lines[-1] = ''
    f1 = '\n'.join(lines)
    f1 += '\n'
    if 'Window(' in f1:  #  a visual.Window() is defined somewhere
        f1 += '\nwin.close()\n'
    if [line for line in lines if 'psychopy' in line and 'core' in line and 'import' in line]:
        f1 += 'core.quit()\n'
    if not demo_license in f1:
        f1 = f1 + demo_license
    return f1