removed bugs in tm.cc