Fixed calculation of error