Changed 'foreach' instead of 'for'