III sent several officials to the Caribbean to review the defenses of the area. Alejandro O'Reilly was sent to Puerto Rico in 1765. O'Reilly recommended many reforms, several of which were implemented: upgrading the fortifications in San Juan; introducing direct, regular pay for the soldiers on the island (up until then, soldiers had been paid by their commanding officers); and professionalizing the militias. He also undertook a complete census of the island (it recorded 44,883 residents, of which 5,037 were enslaved; and 24 towns or villages in the island). In the course of this, he came to realize the importance of contraband in the local economy. To reverse this, O'Reilly recommended developing the legal economy, in particular agriculture, which he found vastly untapped. He wanted to return uncultivated land to the crown and then grant it to persons willing to farm it. In 1784 an intendancy was created in Puerto Rico but, unlike the one created in Cuba, the office was not separated from the governorship. O'Reilly's reforms were most successful in the military sphere. He was able to achieve little economic change, unlike that which took place in neighboring Cuba. The island's economy remained tied to the situado subsidy and foreign trade, something which proved harmful during the interruption in trade caused by the Napoleonic Wars. Early 19th century: revolutions and setbacks The early 19th century presented the dual challenge of Spain suffering invasion by French forces and revolt among its colonies in the Americas. The Peninsular War and the Spanish American wars of independence spurred great innovation in Puerto Rico's government. Puerto Rico's sea ties to Venezuela, due to sailing patterns which made the island the closest port of call from Venezuela, played significantly in this period. The juntas which were established in Venezuela in 1810 corresponded with the cabildos of Puerto Rico. The San Juan cabildo turned down the invitation from the Caracas junta to establish a junta on the island, but the San Germán cabildo always maintained the right to self-rule, should Spain be permanently lost to the French. Some individual Puerto Ricans, such as Antonio Valero de Bernabé, later chose to join the struggle for independence going on in the South American mainland. In response to the junta movement gathering strength on the mainland, the peninsular government gave Governor Salvador Meléndez extraordinary powers to deal with any revolt on the island. At the same time,