sorting input based on node name