The United States and Afghanistan are nearing agreement to rewrite key aspects of their plan for ending U.S. military involvement in the war against Taliban and al-Qaeda fighters here, U.S. and Afghan officials said Saturday.

In a joint appearance, Afghan President Ashraf Ghani and visiting U.S. Defense Secretary Ashton B. Carter acknowledged that they are rethinking the pace of the U.S. military withdrawal, the scope and frequency of U.S. counterterrorism raids and whether they should keep U.S. bases open longer than projected. Although they declined to offer more specifics, they indicated that a new deal could be reached as soon as next month, when Ghani is scheduled to visit Washington to meet with President Obama.

Afghan officials and U.S. military commanders have previously acknowledged pressing Obama for more leeway in determining how quickly the remaining 10,600 U.S. troops in Afghanistan are withdrawn over the next two years. But the comments Saturday by Ghani and Carter were the clearest sign yet that changes are afoot.

“President Obama is considering a number of options to reinforce our support for President Ghani’s security strategy, including possible changes to the timeline for our drawdown of U.S. troops,” Carter told reporters. “Our priority now is to make sure this progress sticks.”

The U.S. military ended conventional combat operations in Afghanistan on Dec. 31. American troops remain in the country to train and advise about 350,000 Afghan security forces in their fight against the Taliban.

U.S. troop levels are currently scheduled to dwindle to 5,500 by the end of this year and to drop to zero by the time Obama leaves office in early 2017, save for a small residual force based at the large U.S. Embassy compound in Kabul.

U.S. military commanders, however, have sought more flexibility in drawing down troop levels over that period as well as broader latitude to conduct counterterrorism raids and airstrikes against Taliban and al-Qaeda targets.

Ghani said he was “gratified” by a recent Obama directive that temporarily kept an extra 1,100 troops in Afghanistan. But he indicated he would not try to lobby Obama to change his mind about completing the U.S. military pullout by the end of his term, saying he “respected” Obama’s decision.

“Our relationship is not defined by the number of troops, but by the comprehensive nature of the partnership,” he added.

Carter took office as defense secretary less than a week ago, but he said this was his 10th visit to Afghanistan during his long career as a Pentagon official.

Standing next to Ghani at the Afghan presidential palace, Carter called counterterrorism a “continuing preoccupation” and said both sides were “rethinking the details of the counterterrorism mission and how the environment has changed here.”

Carter shied from giving specifics, but other U.S. officials noted the recent emergence of a small number of Afghan militants allying themselves with the Islamic State movement based in Syria and Iraq.

Army Gen. John F. Campbell, the commander of U.S. and NATO forces in Afghanistan, said a few former Taliban commanders have “rebranded” themselves as fighters for the Islamic State, noting that one was killed in a U.S. airstrike in Helmand province this month. Although he described the trend as “nascent,” he said U.S. officials recognized how quickly the Islamic State has been able to attract followers elsewhere.

“You saw how fast this went in Iraq,” Campbell told reporters at a separate press conference. “All of us don’t want that to happen here.”

Campbell and Carter lauded Ghani for bringing a measure of political stability to Afghanistan since forming a unity government with Abdullah Abdullah last fall and for his eagerness to work closely with U.S. military officials. Ghani’s predecessor, Hamid Karzai, had a thorny relationship with the Obama administration and frequently spoke out against the presence of foreign troops in Afghanistan.

“The most important factor influencing our thinking is the change represented by the unity government,” Carter said, “and what that means for the promise of certainty, predictability and progress that just a few months ago we couldn’t have planned on.”

Added Campbell: “The difference where we are with Karzai and where we are today is night and day.”