refactoring linear reg