refactored queries for statistics