modularizing graph code