slight improvement in the Graph algorithm