Generic Code to remove duplicates