Fixed foreach bug