Fixed foreach problems