use a context manager for the stats