improved binning algorithm for contiguity builder