Fixed some bugs in the graph reduce routine and fixed issues in tests