Remove some duplicated code in GraphLib.