Fixing the wrong calculation of avg