Fix count queries, +tests