refactor graph initialization