Added some more functions to help implement the gmm