graph code refactoring