refactor Graph impl