Replace unusual way of array iteration