fixed NPE in count queries.