Change to atomic subquery for counting tests