The three barriers were established in the first or second year of the reign of Emperor Tenmu. During the Jinshin War, he had gained an important military advantage over his brother by seizing control of these access points to the capital and thus understood the strategic importances of these chokepoints. The Taihō Code in 701AD stipulated that barriers should have both police and military functions. Each was equipped with a garrison and armory, and was placed under the control of a "kuge" military officer with fourth Court Rank. The purpose of the barrier was not only to prevent invasion from the east, but was also to prevent any rebels from escaping the capital, The barriers were highly closed during times of potential political unrest, such as the illness or death of an emperor. The first time the barrier was actually closed was during the interregnum following the death of Empress Genmei in 722 AD. Other times included the rebellion of Prince Nagaya, the Fujiwara no Nakamaro Rebellion and Kusuko Incident. On the transfer of the capital to Heian-kyō in 789AD, Emperor Kanmu ordered the barriers to be abolished. However, although the troops were withdrawn, the barriers continued to exist, and closures of the gate are recorded at several times well into the middle of the Heian period.