restore distance sorting