Corrected the iteration order.