The Department of Homeland Security was “largely caught by surprise” when President Trump signed the original version of his executive order travel ban against countries with a significant terrorist presence.

A report released Friday by Homeland Security’s Office of Inspector General found that then-Secretary John Kelly had only seen two draft versions of the order just days before the president signed the travel ban order at a Pentagon ceremony Jan. 27, 2017.

“[O]ther than through media reports and a short email summary a few days before its signing, the main implementer of the [executive order’s] provisions — [U.S. Customs and Border Patrol] — had practically no advance notice that the order would issue, or that it would be effective upon signature. Nor did it know exactly what the EO would contain,” the IG report said.

The report said Homeland Security and other departments it needed to work with on the travel ban “had no opportunity to provide expert input in drafting the EO.”

“Answers to critical questions necessary for implementation were undefined when the EO issued. No policies, procedures, and guidance to the field were developed,” the report said. It said the order “took effect immediately” even as travelers from the affected countries were in the air en route to the United States or preparing to travel.

This meant Homeland Security, the State Department, and the Justice Department had to “improvise policies and procedures in real time,” the report said.

The 112-page report said that though CPB agents acted professionally, they did prevent at least 30 travelers from boarding U.S.-bound flights — something that possibly violated two court orders.

The original ban — which has been rewritten multiple times having been struck down by various federal courts — put a 120-day ban on refugees from entering the country and a 90-day ban for most citizens of Libya, Iraq, Iran, Somalia, Sudan, and Yemen.

Currently, the federal government is appealing the latest version of the order to the Supreme Court.

In a response to the report, Homeland Security said in a letter to the IG: “It is important for Congress and the public to know that DHS did not countenance any violation of a court order, including those specifically discussed in this report. Any implication or statement to the contrary is unfortunate and misleading.”