Fix crash and make scan opt faster.

It was iterating over the graph too frequently. Now everything is in an EQ, that will loop only once over all nodes, but will re process all new nodes added in the graph. That way scan opt that depend on previous will continue to work.