Sort the nodes