faster if we don't eval length every iteration

also we remove elementIndex from the upper scode and
we use it only in the iteration