BUFFALO, Minn. – Armed with four pipe bombs, one handgun and a Ziploc bag full of ammunition, Gregory Ulrich caught the public bus outside his motel Tuesday morning and rode the short trip to Allina Health Clinic.

Ulrich shot five clinic workers and set off three of the explosive devices — two in the lobby, a third in an adjacent workstation — in about six minutes between the time he entered the building and surrendered to the officers arriving in the parking lot, according to a criminal complaint filed in Wright County on Thursday.

The investigation also revealed that despite a restraining order and an arrest for violating it, Ulrich used a permit from the Buffalo Police Department to purchase the handgun, according to a law enforcement source involved in the case who was not permitted to speak on the record.

Ulrich faces seven charges for the brutal attack that left one dead, four injured and a small town reeling that something so horrifying could happen here. The charges include second-degree intentional murder, four counts of attempted first-degree attempted murder, possession of an explosive or incendiary device and carrying a pistol without a permit.

"He went to the Allina clinic with a loaded 9-millimeter semiautomatic handgun. He went to the Allina clinic with some improvised explosive devices equipped with gunpowder with a fuse ignition," Wright County Attorney Brian Lutes said at Ulrich's first court appearance Thursday. "He went to the clinic knowing that he was going to shoot that clinic up. He went to the clinic knowing he was going to ignite those bombs, and that's just what he did."

Ulrich, sitting in a wheelchair, was silent throughout the hearing, other than to pronounce his name. When Wright County District Judge Michele Davis asked if he had anything to say, Ulrich declined.

Davis granted Lutes' request for bail of $10 million without conditions and $5 million with conditions, making it unlikely that Ulrich will be released from jail until the conclusion of the criminal proceeding that lies ahead. His defense attorney raised no objection to either amount.

Ulrich was issued a permit to buy a handgun by Buffalo police, and he used that document to buy the gun he brought to the clinic, according to the law enforcement source.

Despite having been the subject of a restraining order by a doctor at the Allina clinic, and being arrested for violating that order, Ulrich still received the permit because the case was dismissed due to mental incompetency. That determination alone should have prevented him from receiving the permit.

Buffalo police were unable to access further details about the reason for the dismissal, the source added, while declining to say why, other than that police did nothing wrong.

A message for Buffalo Police Chief Pat Budke was not returned Thursday.

Wright County Sheriff Sean Deringer said his office and prosecutors asked the courts this week for permission to release Ulrich's gun-related records, but Judge Stephen Halsey denied that request because the Sheriff's Office and the County Attorney's Office do not have legal standing to compel release of the private records.

"In Minnesota, gun permit [to purchase] data is very private," Deringer said. "So we have to be very careful about what we release. I can't even tell you that he made an application. … I can't even tell you that we don't have data or we do have data."

At a news conference, he praised the more than 70 law enforcement officers from multiple agencies who "fearlessly" entered the volatile scene, along with clinic staffers who rushed to help the victims.

"Probably like no other time in our nation's history have we celebrated our health care workers," Deringer said. "They've been on the front line every day when they come to work. … If you can imagine the health care workers in that clinic, doctors and nurses caring for their own workers in that clinic after they've been shot. I can't imagine what that looked like for them."

The charges provide more details into the events leading up to and directly following the scene in the clinic Tuesday, including allegations that Ulrich recorded a rambling video message shortly before the ambush — which prosecutors say is evidence of premeditation — hinting at grievances with his medical care and stating "his intent to go to that clinic to inflict damage."

After firing into the clinic and igniting the explosives, Ulrich directed officers to "back away and he would surrender." The room smelled of burnt gunpowder when police entered. The five gunshot victims received immediate attention from officers. Three were rushed away by air ambulance, and two were taken in ground vehicles to hospitals. Investigators determined a "cylinder-shaped object" ripped a large hole through the lower part of the exterior sliding door leading to the lobby.

Law enforcement deflected questions about why red flags in Ulrich's past went unchecked. Police reports show him calling his former doctor three times a day, threatening a mass shooting, to blow things up and act out other revenge scenarios in 2018, apparent payback for a back surgery he believed was unnecessary. The doctor called police and obtained a restraining order, but Ulrich repeatedly returned to the hospital campus and scared other employees. He was arrested at least once for violating the restraining order, but the charges were dropped after the courts deemed him mentally incompetent.

"While I know that we have had previous threats by Mr. Ulrich, I also want you to know that there has been nothing recent in the past several months or even a year that we would have taken immediate action, or try to circumvent or prevent what happened Tuesday morning," said Deringer. "If we are going to push blame, I ask that people push blame where blame is due, and that's on the suspect that decided to go into a Buffalo clinic to victimize people who are truly trying to help their communities every day."

Ulrich had dozens of interactions with police. A local church called police after he sent it a disturbing letter. He was convicted of two DWIs, an open-bottle offense and crimes related to possessing illegal drugs, including huffing glue in a public park, according to court and police records.

Lutes said most of Ulrich's behavior rated below felony level — meaning they were dealt with by police and city prosecutors — and his office had not encountered him since a 2006 drunken driving incident.