refactor linear regression codes