Querying collections efficiently