Moved linear regression to function