Added a foreach instead of for loop