Data manipulation code extracted form gmm.c