By 1642, the Güshri Khan of Khoshut Khanate had reunified Tibet under the spiritual and temporal authority of the 5th Dalai Lama of the Gelug school. In 1653, the Dalai Lama travelled on a state visit to the Qing court, and was received in Beijing and "recognized as the spiritual authority of the Qing Empire". The Dzungar Khanate invaded Tibet in 1717, and were subsequently expelled by Qing in 1720. The Qing emperors then appointed imperial residents known as "ambans" to Tibet, most of them ethnic Manchus that reported to the Lifan Yuan, a Qing government body that oversaw the empire's frontier. During the Qing era, Lhasa retained its political autonomy under the Dalai Lamas. About half of the Tibetan lands were exempted from Lhasa's administrative rule and annexed into neighboring Chinese provinces, although most were only nominally subordinated to Beijing.