another fix to foreach bug