Improved the function to cancel invalid chainings.
Refuctored proof_graph.*