rewrote the EliminateDuplicates function from the beginning, it still needs some changes though