Readd old bestDistance function