Initial port of glm, passes simple tests.