What remained of the royalist army retreated, and while Juan de O’Donoju was cornered in the fortress of San Juan de Ulúa,[17] he hastily negotiated a treaty with Iturbide, called the Treaty of Córdoba.[14] Similar to the Plan de Iguala, this document guaranteed autonomy for New Spain within the Spanish Empire under the Bourbon dynasty. This successor state would invite Ferdinand VII to rule as emperor or, in default, his brother Don Carlos. If both refused, a suitable monarch would be searched for among the various European royal houses. In the meantime, a regency would replace the viceroy. All existing laws, including the 1812 Constitution, would remain in force until a new constitution for Mexico was written.[11]