fix issues with weighted least squares