refactoring disjointset