small refactoring + UnionFindImprovements
some improvements)