Add more general shorter_distance function