added dist2 and vector sorting