added better saving and more reliable statistic management