Updated distance logic