added quadratic time mmd