refactor graph.js