Convert to foreach loop