Fixed a bug in calculating dt[i]