using for each on loop

update the code to for each to get cleaner.