The state of affairs in the early 16th century, increased trade routes elsewhere and the ossification of the social hierarchy and legal structures contributed to the decline in trade. Frequent quartering of Imperial, Swedish and League soldiers, the financial costs of the war and the cessation of trade caused irreparable damage to the city and a near-halving of the population. In 1632, the city, occupied by the forces of Gustavus Adolphus of Sweden, was besieged by the army of Imperial general Albrecht von Wallenstein. The city declined after the war and recovered its importance only in the 19th century, when it grew as an industrial centre. Even after the Thirty Years' War, however, there was a late flowering of architecture and culture – secular Baroque architecture is exemplified in the layout of the civic gardens built outside the city walls, and in the Protestant city's rebuilding of St. Egidien church, destroyed by fire at the beginning of the 18th century, considered a significant contribution to the baroque church architecture of Middle Franconia. After the Thirty Years' War, Nuremberg attempted to remain detached from external affairs, but contributions were demanded for the War of the Austrian Succession and the Seven Years' War and restrictions of imports and exports deprived the city of many markets for its manufactures. The Bavarian elector, Charles Theodore, appropriated part of the land obtained by the city during the Landshut War of Succession, to which Bavaria had maintained its claim; Prussia also claimed part of the territory. Realising its weakness, the city asked to be incorporated into Prussia but Frederick William II refused, fearing to offend Austria, Russia and France. At the Imperial diet in 1803, the independence of Nuremberg was affirmed, but on the signing of the Confederation of the Rhine on 12 July 1806, it was agreed to hand the city over to Bavaria from 8 September, with Bavaria guaranteeing the amortisation of the city's 12.5 million guilder public debt. After the fall of Napoleon, the city's trade and commerce revived; the skill of its inhabitants together with its favourable situation soon made the city prosperous, particularly after its public debt had been acknowledged as a part of the Bavarian national debt. Having been incorporated into a Catholic country, the city was compelled to refrain from further discrimination against Catholics, who had been excluded from the rights of citizenship. Catholic services had been celebrated in the city by the priests of the Teutonic Order, often under great difficulties.