modification in TDT_magic.py