add linear regression function finally! And lots of tidy up.