2. In 1267, in the Song Dynasty, Shanghai was raised to township status, with a military garrison, within Huating County. In 1277, Shanghai township was chosen as the location of one of seven customs authorities across the empire to handle overseas trade; the surrounding Huating County was raised to prefecture level. The location of the customs office (which later became the office of Shanghai's county government), became a center around which the Old City grew.
3. In 1292, when Shanghai gained county status, the Old City became the seat of the new county. Under the Qing, it also became the seat of the local circuit and its administration headed by an intendant ("taotai").
4. The boundary of the Old city was formerly defined by a defensive wall, built in 1554 during Ming Dynasty, in order to protect the town from raids by Japanese pirates. It measured 10 metres (33 ft) high and 5 kilometres (3.1 mi) in circumference. In addition to the local garrison, the city was surrounded by Qing army posts at Jiangning (Nanjing), Jingkou (Zhenjiang), Hangzhou, and Zhapu.