refactoring + adding code for deleting duplicates from a set