small refinements to improve performance and reduce memory usage during stats computation