Refactoring of GLM. In particular, created some functions