faster if we don't eval length every iteration

also removed elementIndex from the upper scope given
that we use it only in the iteration