Refactoring of collecting statistics on QueryState