refactored merge_graphs(), moved token renaming into a function.