Major fixes for the graph algorithm for testing