added generalized mdm algorithm