UNITED NATIONS (AP) — The U.N. envoy for Libya said Thursday he is confident that competing parliaments in the North African country "are close to a consensus" on a framework to end their political standoff.

Ghassan Salame told the Security Council that the U.N. has convened two sessions of the rival bodies to try to agree on amendments to a 2015 peace agreement, which both sides agree is the only way to end the stalemate.

Libya fell into chaos after the ouster and killing of longtime leader Moammar Gadhafi in 2011.

Since 2014, the oil-rich country has been split between rival governments and parliaments based in the western and eastern regions, each backed by different militias and tribes.

A U.N.-brokered deal in December 2015 to create a unity government failed, though talks have been taking place to form an administration to lead the country ahead of elections.

Salame, who proposed the amendments, said that since the two meetings convened by the U.N., the rival bodies have made "much progress," though "a few remaining points are still to be agreed."

"I am quite confident we are close to a consensus," he said.

Salame stressed that any method to select a new Presidency Council and government "must be transparent and fair" and that there must be an "open and competitive process."

Libya's divisions have empowered hundreds of militias to become the real powers as human trafficking, fuel smuggling and terrorists have thrived.

But in late July, President Fayez Sarraj of Libya's internationally recognized unity government in the west and eastern military leader Gen. Khalifa Hifter met in Paris and committed to a cease-fire.

They also agreed to work toward presidential and parliamentary elections and to find a roadmap for securing the lawless country against terrorism and trafficking.

Libya's parliament, which was elected in 2014, has refused to give its vote of confidence to the government headed by Serraj. It insisted on amending a divisive article in the 2015 peace agreement that keeps the command of the army under the parliament instead of giving it to Serraj.

Salame told the Security Council there also has been progress on holding a National Conference in February, possibly inside Libya.

It will give Libyans from across the country "to come together in one place ... and to agree on the tangible steps required to end the transition," he said.

"As for elections, we are intensively trying to establish the proper political and technical conditions for their occurrence," Salame said.

He stressed that elections should not take place "until we are certain that they will not add a third parliament or fourth government."

Salame said the Constitutional Drafting Assembly has completed a draft and "the constitutional process must now move forward."

The U.N. envoy was highly critical of the treatment of refugees in Libya and migrants trying to get to Europe. He urged the government to find a solution that respects their rights and the rights of host communities in the country.

"Migrants continue to be subjected to extreme violence, torture, rape, killings, extortion, forced labor and other grave abuses inside and outside official places of detention," Salame said. "We have seen an increase in the number of people arbitrarily detained in a system with no accountability or due process."