Croatia's border with Hungary was inherited from Yugoslavia. Much of the border with Hungary follows the Drava River or its former river bed; that part of the border dates from the Middle Ages. The border in Međimurje and Baranya was defined as a border between the Kingdom of Hungary and the Kingdom of Serbs, Croats, and Slovenes, later renamed the Kingdom of Yugoslavia, pursuant to the Treaty of Trianon of 1920. The present outline of the border with Bosnia–Herzegovina and border with Montenegro is largely the result of the Ottoman conquest and subsequent recapture of territories in the Great Turkish War of 1667–1698 formally ending with the Treaty of Karlowitz, as well as the Fifth and Seventh Ottoman–Venetian Wars. This border had minor modifications in 1947 when all borders of the former Yugoslav constituent republics were defined by demarcation commissions implementing the AVNOJ decisions of 1943 and 1945 regarding the federal organisation of Yugoslavia. The commissions also defined Baranya and Međimurje as Croatian territories, and moreover set up the present-day border between Serbia and Croatia in Syrmia and along the Danube River between Ilok and the Drava river's mouth and further north to the Hungarian border; the Ilok/Drava section matched the border between the Kingdom of Croatia-Slavonia and Bács-Bodrog County that existed until 1918 (the end of World War I). Most of the border with Slovenia was also defined by the commissions, matching the northwestern border of the Kingdom of Croatia-Slavonia, and establishing a new section of Croatian border north of the Istrian peninsula according to the ethnic composition of the territory previously belonging to the Kingdom of Italy.