prevent foreach bug