fixed foreach loop