add Least squares unit test, clean code