Members of a Spanish terror cell bought knives and an ax between the first and second fatal attacks in the country's Catalonia region last week, court documents show.
The detail came to light on Tuesday as National Court Judge Fernando Andreu issued orders to jail two of the surviving suspects without bail and provisionally freed another.
A fourth suspect was ordered held in police custody for another 72 hours.
Fifteen innocent people were killed in the vehicle attacks in Barcelona and the seaside town of Cambrils. In addition, the Barcelona attacker and five suspects in the Cambrils attack were killed by police.
The documents say the cell was forced to improvise or carry out alternate plans of violence after the house where they were making bombs exploded on Wednesday night.
The judge said in the order released by the National Court late Tuesday: "The blast truncated the initial plan of the terrorists and precipitated the succession of subsequent events."
Let our news meet your inbox. The news and stories that matters, delivered weekday mornings.
Thirteen people were killed when Younes Abouyaaqoub, 22, allegedly drove a van through Barcelona's crowded Las Ramblas promenade on Thursday. Police say he then hijacked a car and fatally stabbed its driver while making his getaway.
Abouyaaqoub was fatally shot by Catalan police on Monday. Police said that when Abouyaaqoub was confronted near a vineyard he opened his shirt and shouted "Allahu Akbar" while wearing a suspicious belt, and police shot him.
Officials have said that Abouyaaqoub was part of a 12-man extremist cell, along with an imam who was one of two people killed in a house explosion in Alacanar, a town around 100 miles southwest of Barcelona.
Five of the 12 suspects were shot dead by police in the seaside town of Cambrils, where a second vehicle attack left one pedestrian dead hours after the Barcelona van attack.
Andreu said there was enough evidence to hold 21-year-old Mohamed Houli Chemlal and 28-year-old Driss Oukabir on preliminary charges of causing homicides and injuries of terrorist nature and of belonging to a terrorism organization.
The judge also said in a document seen by The Associated Press that Houli Chemlal also was held for dealing with explosives.
And Sahl El Karib, the owner of a cybercafé in Ripoll, the Pyrenees hometown to most of the members of the alleged cell, was ordered to remain in custody under arrest for at least 72 more hours while police inquiries continue.
Meanwhile, the judged ruled the evidence to keep holding suspect Mohamed Aalla was "not solid enough," and he was freed.
Chemlal and Oukabir identified the imam as Abdelbaki Es Satty and said he was the ideologist of the 12-man cell, a Spanish judicial official said.
Es Satty and another man accidentally blew themselves up while preparing explosives in a house in the coastal town of Alcanar, around 100 miles southwest of Barcelona, officials said.
In the Alcanar house, police found 100 tanks of butane gas and materials to make TATP, an explosive frequently used in attacks by the terror group ISIS. The terror group has claimed responsibility for the attacks in Barcelona and in Cambrils.
Oukabir and the other two surviving suspects who testified Tuesday, Aalla and El Karib, denied being part of the cell, said the court official, who was not authorized to speak about ongoing cases and requested anonymity.