fix counts query, closes #30