Refine the code of Graph