Fixed computation of avg