modified for the avg case
took the case of the avg and improved it