improved nested foreach()