Update working one.

This code works with probabilistic bugs. also plots the graph, must be proofed for correctness...!