Refactor graph generator