Simplify `p.T` function and inline `setResultIndex`