fix foreach bug