Changed TagStat to use single query for update

- Added tests
- Extracted TagStat update to util module