adding add_average method and solving iteration bug by replacing definition of t