With a population density of 69/km2, slightly more than a third of the national average, Sardinia is the fourth least populated region in Italy. In the recent past the population distribution was anomalous compared to that of other Italian regions lying on the sea. In fact, contrary to the general trend, most urban settlement, with the exception of the fortified cities of Cagliari, Alghero, Castelsardo and few others, has not taken place primarily along the coast but in the subcoastal areas and towards the centre of the island. Historical reasons for this include the repeated Saracen raids during the Middle Ages and then Barbary raids until the early 19th century (making the coast unsafe), widespread pastoral activities inland, and the swampy nature of the coastal plains (reclaimed definitively only in the 20th century). The situation has been reversed with the expansion of seaside tourism; today all Sardinia's major urban centres are located near the coasts, while the island's interior is very sparsely populated.