factoring out kruskal algorith.
More refactoring.
Refactoring.
More refactoring.