Fixed error with foreach and array using references