fix distance sorting