refactor graph class