refactored distance to metrics