added distance sorting method