Fixed foreach errors