for Queen Mother Dorothea. k After Dorothea's death in 1571, the castle passed into the ownership of Hans II, Duke of Schleswig-Holstein-Sonderburg (also known as Hans the Younger). Under his rule, the castle became the center of a tiny duchy, Schleswig-Holstein-Sonderburg. This, however, was divided after his death in 1622. The castle remained in the hands of the dukes of Southern Jutland until 1667, when the ruined duchy of Sønderborg was attached to the Danish throne and the castle became a Danish estate. The duchy’s representative, the Prefect (Amtmanden), took up residence at the castle. It was otherwise more or less unused in the years 1667-1718. In 1718-1726, Frederik IV had the castle rebuilt in Baroque style by contractor general Wilhelm von Platen. The Blue Tower was demolished in 1755, and in 1764 the castle passed into the hands of the Duke of Augustenborg; but, contrary to expectations, the castle did not become the duke's residence. Instead, it was rented out as a warehouse. During both the first and the second Slesvig wars (1848-1850, 1864), Sønderborg Castle was used as a camp hospital and for quartering Danish troops. After the war of 1864, the province and the castle became Prussian property and served as barracks from 1867 until the area was reunified with Denmark in 1920. The last duke of Augustenborg, Ernst Günther, allowed Sønderborg County Museum to move into a part of the castle in 1920. The next year, the Danish state bought the castle from the Duke, taking over the castle in 1921 and allowing several institutions to use it as long as they paid heed to the expanding museum. In 1945 and 1946, the castle was used as an internment camp for persons charged with offenses to the state. The Royal Inspectors of Listed State Buildings, Peter Koch and Jørgen Stærmose, conducted a thorough restoration of the castle from 1964 to 1973, returning it to the Baroque form it had been given by Frederik IV in the 1720s. The windows from the barracks era were even replaced with "masks", windows with broad wooden frames made of planks like the ones in Platen's castle. The museum and grounds Since 1921 Sønderborg Castle has been the home for The Sønderborg Castle Museum (Museet på Sønderborg Slot), which is the main museum for the former Duchy of Slesvig. The museum houses local and regional history collections from the Middle Ages