Change foreach loop

as it is faster to work directly on values