foreach bug fixed