UVALDE, Texas (AP) — Nearly 20 officers were in a hallway outside of the classrooms at a Texas elementary school for more than 45 minutes before agents used a master key to open a door and confront a gunman, authorities said Friday.

The on-site commander believed the gunman was barricaded in a classroom at Robb Elementary School in Uvalde during Tuesday’s attack and that the children were not at risk, Texas Department of Public Safety Director Steven McCraw said at a news conference.

“Of course it was not the right decision. It was the wrong decision,” McCraw said.

Children repeatedly called 911 asking for help, including one who pleaded: “Please send the police now.”

It is unclear why the school’s student resource officer was not on campus, but upon hearing the 911 call about a man with a gun he immediately drove to the scene and sped to the back of the school to a man who he thought had a gun but realized it was a teacher and not the suspect.

“In doing so, he drove right by the suspect who was hunkered down behind a vehicle where he began shooting at the school,” McCraw said.

McCraw said the gunman had over 1,000 rounds of ammo and fired at least 100 rounds based on audio evidence.

U.S. Border Patrol agents eventually used a master key to open the locked door of the classroom where they confronted and killed the gunman, 18-year-old Salvador Ramos, McCraw said.