Refactored queries with counts