fixed an error in the optimize_coeff method and completed the while loop