begin to fix foreach bug