Fix overflow of range counts calculation