Added security and more to 'foreach'