A revised Brexit deal has been agreed by the UK and EU. What is in it?
All sides want to avoid the return of a "hard border" after Brexit between Northern Ireland and the Republic of Ireland - with checks and infrastructure which could be targeted by paramilitary groups.
Coming up with solutions to this - acceptable to all sides - has been very challenging.
The new protocol replaces the controversial Irish backstop plan in Theresa May's deal. Much of the rest of that deal will remain.
Here are some of the key new parts:
What does the deal mean for Northern Ireland?
The whole of the UK will leave the EU customs union. This means the UK will be able to strike trade deals with other countries in the future.
There will be a legal customs border between Northern Ireland and the Republic of Ireland (which stays in the EU). But in practice the customs border will be between Great Britain and the island of Ireland, with goods being checked at "points of entry" in Northern Ireland.
Duty (tax) won't automatically have to be paid on goods coming into Northern Ireland from Great Britain.
But where something is "at risk" of then being transported into the Republic of Ireland (which is part of the EU customs union), duty will be paid.
A joint committee made up of UK and EU representatives will decide at a later date what goods should be on the list.
It might be that duty is paid on goods that do not end up being sent on from Northern Ireland into the EU. The UK would be responsible for whether to refund the duty in these circumstances.
Ordinary people won't have their baggage checked and duty won't apply to individuals sending goods to other people.
There will also be limits agreed by the joint committee on the amount of help the government can give to Northern Irish farmers. The figure will be based on the amount they currently receive from the EU's Common Agricultural Policy.
Who enforces EU rules?
This will be done by UK officials at "points of entry into" Northern Ireland, but the EU will have the right to have its own officials present.
It seems those EU officials may be able to overrule UK officials. "Where the Union representative requests the authorities of the United Kingdom to carry out control measures in individual cases for duly stated reasons, the authorities of the United Kingdom shall carry out those control measures."
Does Northern Ireland get a say?
Because Northern Ireland will be set apart from the rest of the UK when it comes to customs and other EU rules, the deal gives its assembly a chance to vote on these provisions.
After four years, Northern Ireland will have the opportunity to vote on customs and state aid rules.
If the Northern Irish Assembly votes against them, they would lose force two years later during which time the "joint committee" would make recommendations to the UK and EU on "necessary measures".
If the Assembly accepts the continuing provisions by a simple majority, they will then apply for another four years. If the deal has "cross-community support" then they will apply for eight years, or until a new agreement on the future relationship is reached if that comes sooner.
The deal defines cross-community support as at least 51% each of unionist and nationalist Assembly members voting in favour, or at least 40% of members from each designation if in total at least 60% of members have voted in favour.
The UK government has said that if the Northern Ireland Assembly is still not sitting at that point, it will make alternative arrangements to make sure a vote can take place.
What has been agreed on VAT?
The new agreement says that EU law on value added tax (VAT - a tax added when you make purchases) will apply in Northern Ireland, but only on goods, not services.
But it also allows Northern Ireland to have different VAT rates to the rest of the UK, which would not normally be allowed under EU law.
For example, if the UK decided to reduce the VAT on household fuel to zero, Northern Ireland would still have to keep it at 5%, which is the EU minimum.
It also means that Northern Ireland may get the same VAT rates on certain goods as the Republic of Ireland, to stop there being an unfair advantage on either side of the border.
Some things have not changed:
Much of Mrs May's original Brexit deal will remain as part of the overall agreement. Some of the key areas are:
The transition - a period of time during which all of the current rules stay the same allowing the UK and the EU to negotiate their future relationship - is due to last until the end of December 2020.
The UK will need to abide by EU rules and pay into the EU budget, but will lose membership of its institutions.
The transition can be extended, but only for a period of one or two years.
Both the UK and EU must agree to any extension.
UK citizens in the EU, and EU citizens in the UK, will retain their residency and social security rights after Brexit.
Freedom of movement rules will continue to apply during transition. This means that UK nationals will be able to live and work in EU countries (and EU nationals will be able to live and work in UK) during this period.
Anyone who remains in the same EU country for five years will be allowed to apply for permanent residence.
The UK will have to settle its financial obligations to the EU.
There is no precise figure but the biggest part of this "divorce bill" will be the UK contributions to the 2019 and 2020 EU budgets.
As Brexit was delayed from 29 March to 31 October 2019, some of that money has been paid as part of the UK's normal membership contributions already. The Office for Budget Responsibility (OBR) estimates that the bill is now around £33bn (down from £39bn).
The OBR expects that most of the money - around three-quarters of the total - would be paid by 2022, with some relatively small payments still being made in the 2060s.