edited foreach loop