Few performance changes to vector/distance logic