Belgium and the Netherlands have agreed to swap land end their border dispute. The dispute began because of the change in course of a river along which Belgium’s border was drawn, when it gained independence from the Netherlands in 1830.

The countries will cede uninhabited stretches of land according to the change in course of a river that flows through both nations. The river is called the Meuse in French and the Maas in Dutch. It river was straightened in 1961 for ease of navigation, but as a result, parts of each country’s territory ended up on the other side of the river.

To end the dispute Belgium will get three hectares of land against the two peninsulas of 16 hectares (40 acres) that it will give to the Netherlands. A Belgian foreign ministry spokesman told Reuters, “It was just not logical that that small piece was still part of Belgium.”

The countries signed a treaty to the effect on Monday. The changes will come into affect from 2018. The land swap, however, excludes Baarle-Hertog, a village in Belgium that shares its border with Baarle-Nassau in the Netherlands. It has several exclaves (a piece of land belonging to a political entity but not physically attached to it) in the Dutch country. None of the land parcels that constitute the village are contentious. Several houses in the village are divided between Belgium and Netherlands.