It is not clear where and when the crossbow originated, but it is believed to have appeared in China and Europe around the 7th to 5th centuries BC. In China the crossbow was one of the primary military weapons from the Warring States period until the end of the Han dynasty, when armies composed of up to 30 to 50 percent crossbowmen were not unheard of. The crossbow lost much of its popularity after the fall of the Han dynasty, likely due to the rise of the more resilient heavy cavalry during the Six Dynasties. One Tang dynasty source recommends a bow to crossbow ratio of five to one as well as the utilization of the countermarch to make up for the crossbow's lack of speed. The crossbow countermarch technique was further refined in the Song dynasty, but crossbow usage in the military continued to decline after the Mongol conquest of China. Although the crossbow never regained the prominence it once had under the Han, it was never completely phased out either. Even as late as the 17th century, military theorists were still recommending it for wider military adoption, but production had already shifted in favor of firearms and traditional composite bows.