fix tde bugs and improve performance