refactoring graph measure code