Reduced memory utilization

Delayed the pairwise distance calculations until they are
required. This resulted in a reduced memory footprint.
Memory complexity should have gone from O(n^2) to O(n).