Changed distance to min and max distance