Changed loop order