Changes from counter to foreach loops