add the function for updating average