moving array_unique to above the foreach that creates Set objects