Separated functon for stats_update