Correction of scope of variables and otimizations in TMX classes