added calculation of average error