fixed calculate_average