Refactored batch query.