Converted a for to foreach