fixed maths error, and added rounding of average