refactored to use glm instead of lm