Deleted unneeded part and arranged the order of sbstituting dned[i] and tcode.