moving totalStats initialization to proper scope