After two long days of debate, a majority of MPs have voted in support of the general principles of the government's repeal bill which will extract the UK from EU law in time for Brexit.
The bill - formally known as the European Union (Withdrawal) Bill - passed the "second reading" stage by 326 votes to 290. This means a majority of MPs support the bill's broad principles, but not necessarily every little detail.
The government says it is essential to carry out Brexit. Opposition MPs have called it a power grab.
There is a long road ahead before the repeal bill becomes law. A lot of MPs, including many who backed the bill at second reading, want to amend it at the next stage of parliamentary scrutiny.
A long list of amendments has been published on the House of Commons website. Not all will get through. But some - especially those backed by Conservatives - could mean big changes. Here are some of the key points of contention.
Too much power to ministers?
The bill repeals the 1972 law which took the UK into the EU, and copies EU legislation into domestic law to ensure a smooth transition the day after Brexit. However, a simple copy-and-paste approach would not be enough: swathes of UK law "will no longer work" on exit, the government says. For example, many bits of law refer to EU institutions.
Therefore the government wants to avoid a "black hole in our statute book" by making "corrections" to EU laws: copy, paste, edit.
The bill grants ministers powers to tweak existing laws without the usual safeguards. Sir Keir Starmer, Labour's Brexit spokesman, says the bill is, in effect, a "blank cheque" which gives ministers too much power.
The government points to safeguards written into the bill. The correcting powers "can be used only to correct problems with the statute book arising directly from our withdrawal from the European Union," said Brexit Secretary David Davis.
"Ministers cannot use it simply to replace European Union laws that they do not like," he said, pointing to various restrictions. For example powers cannot be used to create serious criminal offences, impose new taxes, or amend the 1998 Human Rights Act.
Hilary Benn, a Labour MP, thinks this does not go far enough.
"How can we accept a bill if on the one hand ministers get up and say, 'Look at the safeguards; they are in the legislation,' and on the other, they propose in another part of the bill to give themselves the power to remove every one of those safeguards, if they are so inclined?"
Not enough scrutiny
Critics also say the bill could mean massive changes being made to UK law without appropriate levels of scrutiny. After the copy and paste, the tweaks will be made by ministers using "statutory instruments".
These are a kind of law usually passed without a debate or vote on the floor of the House of Commons. Statutory instruments can be voted down, though this rarely happens. The government says the repeal bill will involve 800-1,000 statutory instruments, though the opposition says this number could be higher.
These devices are primarily used for technical and non-contentious pieces of legislation. "[The repeal bill] aims to maintain the laws that we currently have... it is primarily technical in that respect," said David Davis.
Lots of changes could indeed be uncontroversial - like changing the name of an EU regulatory body to a UK one - but not everything.
"The secretary of state is keen to portray the bill as a technical exercise converting EU law into our own law without raising any serious constitutional issues about the role of Parliament," said Sir Keir Starmer. "Nothing could be further from the truth."
Statutory instruments could be used to change primary legislation passed by MPs as well as making tweaks to EU laws carried over - granting so-called "Henry VIII powers" to ministers.
Therefore some MPs have called for a beefed up "sifting" process for all the new statutory instruments. A long amendment has been put forward which would "set up a triage and scrutiny system under the control of Parliament, for determining how Statutory Instruments under Clause 7 of the bill will be dealt with."
Crucially this tweak is backed by several Conservative MPs, meaning it has a good chance of becoming law.
Leaving the single market and customs union
While we are set to leave the EU in March 2019, the exact nature of the future arrangement is unknown. Ministers accept there will be some kind of transitional arrangement after Britain leaves the EU and before the details of a future relationship are decided.
Labour wants the UK to stay in the EU's single market and customs union during a transitional period. This is hard to reconcile with the repeal bill, which kicks in on the Brexit day. Several Labour MPs gave this as a reason to oppose the bill at second reading.
Conservative Europhile Ken Clarke was the only member of his party to vote against the bill giving the government permission to trigger Article 50 earlier this year.
He abstained this time around, arguing "we should stay in the single market and the customs union until we know that we can smoothly transfer to some new and equally beneficial arrangement".
The government's response to this is simple - leaving the single market and customs union in 2019 is government policy - so the wording of the bill is a feature, not a bug. Ministers Philip Hammond and Liam Fox, from opposite wings of the Conservative Party, confirmed this policy last month.
The government wants to get on with its top Brexit priorities: ending the free movement of people, ending the jurisdiction of the European Court of Justice in the UK, and signing new trade deals. Ministers don't think these goals are compatible with staying in the single market and customs union beyond 2019.
Losing legal rights
Since the referendum last year, ministers have insisted Brexit will not mean watering down workers' rights, many of which are underpinned by EU rules. But in the repeal bill debate several MPs argued that the repeal bill will weaken the legal force behind these rights.
At the moment British citizens can go to European courts, putting these rights on a higher plane than other bits of law. "[The rights] do not survive with their enhanced status; they survive only in delegated form," said Keir Starmer. "From the date of this bill, they are amendable by delegated legislation."
The repeal bill does transfer rulings from European courts into UK law, but subsequent legal challenges will have to be based on precise legal cases, not on broader principles.
"There is no right of action in domestic law on or after exit day based on a failure to comply with any of the general principles of EU law," the bill says. Several Conservative MPs, including former attorney general Dominic Grieve, want to delete this line.
Grieve argues the wording as things stand would mean a "marked diminution in the rights of the individual and of corporate entities".
The government says the rights currently enjoyed by Brits have a range of origins - UK law, EU law, international law - all of which will be continued under the repeal bill. Ministers believe removing the right to rely on "general principles" of EU law is an inevitable consequence of leaving the EU.
Another amendment with Tory backing would allow the EU's Charter of Fundamental Rights to continue to apply in the UK.
Critics say quitting the charter would weaken human rights protections in the UK. But all the rights included in the charter will be copied and pasted on to the UK's statute book. David Davis says: "Why on earth we need an extra layer of declaratory law, I do not know."
Over the past two decades, power has been transferred from Westminster to the devolved administrations in Edinburgh, Cardiff and Belfast.
While some areas - like currency and defence - are the sole preserve of the UK government, others are devolved. For example, in Scotland, agriculture is devolved. But lots of agricultural laws are set by the EU.
Under the text of the repeal bill, after Brexit these powers will flow back to Westminster rather than the devolved legislatures.
David Davis says this is a "transitional arrangement", and has pledged to involve the devolved administrations closely in shaping the future arrangements, though they will not have a veto.
Four nations making four different sets of rules would create barriers to doing business within the UK, says Mr Davis. "The bill therefore provides certainty and continuity for people across the UK by recreating in UK law the common frameworks currently provided by EU law, and providing that the devolved institutions cannot generally modify them."
This restriction has been described by opposition politicians as a "power grab".
Wayne David, a Welsh Labour MP, said "power is going from Brussels to London, bypassing and therefore undermining devolution".
The SNP's Patrick Grady called the repeal bill a "fundamental breach of the principles" of the 1998 law setting up the Scottish parliament.
The government says the process will eventually result in a "significant increase in the decision-making power of each devolved administration".
Fining the government
At the moment the EU can fine the UK government for breaching its rules - a legal battle over air pollution has been going on for several years.
When Britain leaves the EU and the remit of the European Court of Justice, this threat will disappear.
"An alternative system does need to be introduced," said Conservative MP Zac Goldsmith, who backed Leave in last year's referendum.
"If the present or a future government fail, for example, to stay within air pollution limits, it must be possible for sanctions to be applied and for that government to be held to account... that is a core ingredient in any healthy democracy."
His colleague Richard Benyon agrees.
"To ensure that the environment is protected, a proper body with the ability to audit the government, working with non-governmental organisations, needs to be put in place."
Mr Benyon voted for the bill at second reading, like virtually all Conservative MPs, but wants to "improve" it at the committee stage by making amendments to address this concern.
What's the alternative?
"Labour voted for the article 50 legislation, because we accept the referendum result. As a result, the UK is leaving the EU. That we are leaving is settled. How we leave is not," said Sir Keir Starmer on the first day of debate.
"This bill invites us to surrender all power and influence over that question to the government and to ministers. That would betray everything that we are sent here to do."
New Conservative MP Vicky Ford directed a simple question at the shadow Brexit secretary: "What is he proposing?"
The government says it is impossible to carry out Brexit without some kind of repeal bill extracting the UK from EU law.
Ministers appear to be in "listening mode", and accept there are some valid criticisms over the bill's details. Some of the amendments - especially those proposed by Conservative MPs - have a good chance of being passed.
But they say voting down the bill in its entirety would make it very hard for the government to carry out Brexit ahead of March 2019. Other laws - on customs, immigration, and other areas - cannot be passed until this fundamental issue is sorted out.
With this hugely contentious bill, a government without a majority, and fractious coalitions forming and dissolving across party lines, Westminster could be seeing lots of late nights this autumn.