Initial version for TRSM; still have some bugs