Remove duplicated code

Introduce update_stats() and remove correspondng
duplicated code.

No functional change.