Fix spelling in reference of characters array, implemented function to sort distances