Fixed average not being calculated correctly