Finally fixed the writing to TE, thanks MrJ

for the help with that :)