replace set with unordered_set + refactoring