adding averaging implementation