Improved the count query statement.