Rewrote the GLM function to be more general