least-squares-fitting bugfix