fixed bug in edge distance calculation