and the County of Barcelona Northern Catalonia formed part of the Spanish Marches, established by Charlemagne as a buffer territory against the Moorish forces. As such, it was divided into feudal counties, Rosselló, Vallespir, Conflent north of the Pyrenees and Cerdanya to the south. By the end of the ninth century, these counties had gained de facto independence from the Carolingian kings and operated as princely states (whose rulers nevertheless retained the title of count). As the seigneury of the counties became hereditary, the total number of Catalan counts fell steadily. One individual often had the charge of several counties, but these were not always transmitted based on primogeniture. Hence Count Miró II the Young, third son of Wilfred I the Hairy, inherited the counties of Cerdanya and Conflent from his father in 897, and the counties of Besalú and Vallespir from his elder brother Sunyer I when the latter became Count of Barcelona in 911. The Counts of Rosselló, in alliance with their cousins the Counts of Empuriés, tried to resist this dilution of their power. However, the Counts of Barcelona steadily gained suzerainty over the other Catalan counts, a process that was virtually complete by the twelfth century. The last Count of Rosselló, Girard II, left his title to the Crown of Aragon on his death in 1172 to prevent the territory passing to his illegitimate half-brothers. Crown of Aragon and the Monarchy of Spain Royal administration in the Principality of Catalonia under the Crown of Aragon was organized based on vegueries, under the charge of a veguer appointed by the King of Aragon as Count of Barcelona. In Northern Catalonia, the vegueries followed closely the boundaries of the old counties. The district of Capcir was a sotsvegueria, based around the castle of Puigbalador (French: Puyvalador) but subordinate to the vegueria of Conflent. The Treaty of Corbeil of 1258 confirmed the frontier between France and Aragon as the Cerbères, leaving the Occitan district of Fenolheda to France. On the death of King James I the Conqueror in 1276, Northern Catalonia was combined with the Balearic Isles to form a new Kingdom of Majorca, which passed to James II while the rest of the territory of the Crown of Aragon passed to his brother Peter III. This division satisfied neither branch of the family, and the Kingdom of Majorca was retaken militarily by the Crown of Aragon in 1344,