Algorithm has been updated to use the DistanceTree class.