Refactoring graph distance