Fix link distance, fix sort bug