added in-place sort to find_link_lengths