graph related code refactor