update avg algorithm