Should be out of first foreach to avoid repeats.