bug fix FOREACH