Final version of gmm code