use enumerate in place of 'for ti in range(i, tokens.len()) ...'