avoid recomputating indicies on each loop iteration