After the Ottoman defeat in the Great Turkish War and the Treaty of Karlowitz (1699), a separate Kingdom of Slavonia was formed out of the regained territories, confirming the established borders of the Kingdom of Croatia. Pursuant to provisions of the Croatian–Hungarian Settlement of 1868, Slavionia was added to the Kingdom of Croatia-Slavonia—the territory ruled from Zagreb—and the military frontier was abolished. Rijeka was removed from the new kingdom, as the Corpus separatum attached it to Hungary instead. Following World War I and the Treaty of Trianon, Hungary lost Rijeka and Međimurje, as well as other territories, to the newly established Kingdom of Serbs, Croats and Slovenes. The 1921 constitution defined the country as a unitary state and abolished the historical administrative divisions, effectively ending Croatia's autonomy. Međimurje was assigned to Croatia in 1947—when all the borders of the former Yugoslav constituent republics were defined by demarcation commissions, pursuant to decisions of the AVNOJ of 1943 and 1945.