Donald Trump and South Korean President Lee Jae Myung finalized details of their fraught trade deal at a summit in South Korea on Wednesday, and the U.S. president also sounded an optimistic note about a looming summit with China’s Xi Jinping.

“We made our deal, pretty much finalized it,” Trump said at a dinner with Lee and other regional leaders on the sidelines of an Asia Pacific forum.

The allies unveiled a deal in late July under which Seoul would avoid the worst of U.S. tariffs on its imports by agreeing to pump $350 billion of new investments into the United States in return for lower tariff rates.

But talks over the structure of those investments had been deadlocked and both sides had played down expectations for a deal during Trump’s visit.

“Prospects were not bright even last night, and there was dramatic progress on the day,” Kim Yong-beom, South Korea’s top presidential policy chief, told reporters, without providing further details.