Finalized GraphBuilding algorithm.