Simplified the get_sorted_nodes function and added a get_dest function.