Made dist and wdist into functions