responsible for Peru's first lucrative guano exportation. Meanwhile, president Gamarra had been harboring intentions of annexing Bolivia back to Peru and, in 1841, he led an invasion army to Bolivia, only to be defeated and killed by the army of José Ballivián during the Battle of Ingavi, leaving Peru without a leader. During that year various infights among caudillos occurred who constantly proclaimed themselves Presidents. Manuel Menéndez, then Vice President, assumed the presidency, but was overthrown by a coup d'état led by Juan Crisóstomo Torrico in 1842. Soon after, Castilla, along with Domingo Nieto, overthrew Manuel Ignacio de Vivanco during the Battle of Carmen Alto. Nieto assumed the presidency but died a few months later. Castilla assumed the position on February 17, 1844 until December 11 of that year. After defeating the other caudillos around the country, Castilla reinstated Menéndez as President, in order to achieve a constitutional transition to democracy. President of the Republic In 1845, Castilla won the Peruvian presidential elections and was sworn in in April of that year. During this time the guano export boom was rapidly expanding, largely due to treaties signed with the British company Antony Gibbs, which had commercialized the guano in Europe. Important urban projects began during this period too, such as the first railroad from Lima to Callao, which helped in the transportation of the guano from the production centers ready to be shipped abroad. After six years in power, Castilla was succeeded by José Rufino Echenique. In 1854, however, another rebellion was led in Peru's second-largest city, Arequipa, by Castilla himself, who was largely urged by other Peruvian liberals to help in the suppression of slavery in the country. On December 3, 1854, in the city of Huancayo, an abolition of slavery law was passed. As this law was being applied, Castilla confronted and defeated Echenique in the Battle of La Palma on January 5, 1855. In 1859, Peru had a confrontation with neighboring Ecuador over disputed territory bordering the Amazon. Though Peru was considered successful, Castilla failed to secure a definitive agreement with Ecuador and the issue would haunt both countries until the end of the 20th century when the 1997 Peace and Border Treaty of Itamaraty was signed by Peru and Ecuador in Brazil. In December 1860 a new constitution was enacted during Castilla's presidency and became Peru's supreme law until 1920. Castilla's second presidency, therefore, was marked