refactoring graph generation for performance