Added support for distance weighting