The Second French Invasion of Portugal was defeated and the allied armies moved back to the South, the British concentrating at Abrantes and the Portuguese at Castelo Branco. With the intention of cooperating with the Spanish against Marshal Victor, the Anglo-Portuguese forces under Wellesley moved into Spain in the Talavera campaign while Beresford remained on the Águeda River covering the Spanish-Portuguese border. After Wellesley's return, now as Viscount Wellington, following the Battle of Talavera, Beresford re-entered Portugal, where he distributed the army at various locations and established his General Headquarters in Lisbon. From Lisbon he dispatched numerous orders and instructions for the reform of the Portuguese military.