using foreach instead of for loop