Rewrote Average function