Modified foldTGraph and foldTGraphOrd to be tailrec and added some test cases