averaging function WIP