Using foreach instead of for loop