IMPORTANT fix to average calculation