added the averaging function