Change for loop to foreach

Updated in latest commit