Fix to calculate average for each variable.