Work on averaging function