backport upstream countSeries function