taking coeff calc outside loop