tag_parser.py:: added topological sort to assist with handling pairs