distance refactor