fixed issues with count queries