Added another optimisation for fast counting queries.