Updated distance func