The man who took hostages at a Texas synagogue sought to buy drugs and a “machine gun” before the standoff last month that ended with the hostages escaping and the gunman’s death, an FBI agent said in court Wednesday.

Also read: Texas hostages escaped synagogue as FBI SWAT team rushed in

The testimony came during a detention hearing for the Dallas man accused of selling Malik Faisal Akram the handgun he used in his attack on Congregation Beth Israel in the suburb of Colleyville. A federal magistrate ordered the alleged seller, Henry “Michael” Williams, detained ahead of his trial on a charge of being a felon in possession of a firearm.

Williams, 32, was arrested less than two weeks after the standoff ended with an FBI tactical team rushing into the synagogue and fatally shooting Akram just as the hostages made their escape. Authorities said Williams confessed to selling Akram, a 44-year-old British national, the previously stolen pistol.

Also read: Texas Rabbi: Captor grew belligerent late in standoff

During the detention hearing, FBI agent Taylor Page testified that Williams said Akram initially reached out to him seeking to buy methamphetamines and “a machine gun or a weapon that contains a large number of bullets.” Akram explained that he wanted the gun for intimidation to help settle a debt, according to Page.

Page also said that Akram fired his gun at some point during the standoff but did not provide details. Multiple gunshots could be heard in the area around the synagogue soon after the FBI breached the building.

Also read: Colleyville hostage situation: How did the incident unfold?

In court, prosecutors highlighted Williams’ past felony convictions and Page said Williams brokered 10 to 15 other gun sales. Williams’ defense lawyer argued that he could not have known what Akram actually planned to do with the gun and said her client was being blamed for another person’s actions.

Magistrate Judge Rebecca Rutherford ordered Williams be held as a potential danger to the community.