erroneous sum() is replaced by mean()