Implementation of GMM