When the Duchy of Courland split in 1596, Mitau became the residence of Duke Friedrich Kettler of Semigallia. The city again became the capital of the united duchies in 1617. Because the duchy became a vassal of the Polish–Lithuanian Commonwealth from 1561, Mitau was also referred to by the Polish name Mitawa. The Commonwealth's repeated wars with Sweden subjected Mitau to several sieges. Despite the wars, the city grew as a center for trade and industry. As Courland's neighbors increased in strength, however, the duchy and Mitau began to fall under Russia's sphere of influence. The Tsar of Russia, Peter the Great, received a promise from duke Friedrich Wilhelm that he would marry one of the daughters of the tsar's late half-brother. In 1710, Friedrich Wilhelm married Anna Ioannovna (later Empress of Russia), but on his way back from St Petersburg, he took ill and died (1711). Anna ruled as the duchess of Courland from 1711 to 1730. The penultimate duke of Courland, Ernst Johann von Biron, expanded the cultural aspects of Mitau. He constructed the ducal palace and opened the first public library in the city. In 1775 the last Duke of Courland, Peter von Biron, founded the Academia Petrina, which became a cultural center for the country. The duke also encouraged theatrical performances at his court. With the outbreak of the French Revolution in 1789, the citizens of Mitau clamored for more rights. Later, Imperial Russia annexed the city as part of Courland in 1795 during the Third Partition of Poland. As the seat of the Count of Provence, the palace of Mitau was the residence (1798–1801 and 1804–1807) of Louis XVIII before he became the French king in 1814. Although the city was occupied by Prussian troops during the Napoleonic Wars, it was largely spared destruction. Mitau further expanded after the construction of its railway in 1868. The development of its infrastructure encouraged rural Latvians to migrate to the city, as merchants, craftsmen, teachers, and officials. By 1914 Mitau had over 45,000 inhabitants. However, Mitau suffered considerably after the outbreak of World War I in 1914. The spirited defence of Mitau by two battalions of the Latvian Home Guard in 1915 helped inspire the formation of the Latvian Rifles. German troops occupied the city during the war, and British prisoners of war, sent there as forced labour, suffered atrocious conditions and treatment. After the war, in 1919,