added mcd function (from Martin Väth)