Added distMat function