edited to deal with dupes