Corrected a bug in the coefficient calculation