Following the Thirty Years' War that devastated much of the Holy Roman Empire, Frederick William focused on rebuilding his war-ravaged territories. Brandenburg-Prussia benefited from his policy of religious tolerance and he used French subsidies to build up an army that took part in the 1655 to 1660 Second Northern War. This ended with the treaties of Labiau, Wehlau, Bromberg and Oliva; they removed Swedish control of the Duchy of Prussia, which meant he held it direct from the Holy Roman Emperor.