moved from rGLM code base