Calculating mode and mode dsts.