The Zaporizhian Host, in order to leave the Polish–Lithuanian Commonwealth, sought a treaty of protection with Russia in 1654. This agreement was known as the Treaty of Pereyaslav. Commonwealth authorities then sought compromise with the Ukrainian Cossack state by signing the Treaty of Hadiach in 1658, but—after thirteen years of incessant warfare—the agreement was later superseded by 1667 Polish–Russian Treaty of Andrusovo, which divided Ukrainian territory between the Commonwealth and Russia. Under Russia, the Cossacks initially retained official autonomy in the Hetmanate. For a time, they also maintained a semi-independent republic in Zaporozhia, and a colony on the Russian frontier in Sloboda Ukraine.