Fixed incorrect calculation of average