 The King appointed Castelo Melhor his secret notary (escrivão da puridade), a position in which the favourite was able to exercise the functions of first minister.Castelo Melhor overcame the difficulties which had hitherto beset Portugal in the war against Spain, reorganizing the troops (now reinforced by an English contingent by virtue of the English king Charles II's marriage to Catherine of Braganza) and entrusting their command to competent generals.Consequently the Portuguese Restoration War entered a victorious phase for Portugal (1663–65) and Spain began peace negotiations.