foreach loop fix