added error handling and sort the nodes alphabitically