use group by for count correctness