added residual function to linreg struct; tidied up