Now sorts the array in correct order, so that routing can be done