speed up distance calculations

we were loosing a lot of time on building a ranked list of subsets.
This modification speeds it up roughly 50x with 1.5k starting data
blocks, when compared to the previous version.