changed for to foreach