Dist.m function has problem