implemented least squares, should work but untested