Calculating the average value