Changed count_type to 16-bit to avoid integer overflow