Freddie Perez and Tayvon Thomas were on a mission to take out the drug operation at C and Clearfield Streets in Kensington.

They wanted control of the corner, and if they couldn’t get it, they would kill as many of the drug crew’s higher-ups as they could, law-enforcement sources said Thursday.

But their mission had unintended, tragic consequences, police say. Perez and Thomas are accused of a brazen shooting in which Nikolette Gabriela Rivera, the 2-year-old daughter of a rival drug dealer, was killed by one of several bullets fired into her home Sunday afternoon.

As the two men with lengthy criminal records sat in custody Thursday after a frantic manhunt, the extent of the havoc they had wreaked for years came into sharper focus.

Perez, 30, had been a foot soldier in the Clearfield Street crew until he went to prison and felt abandoned by the hierarchy, sources said.

Released in August 2017, he began a one-man shooting war with his former bosses. In the last year, he shot at several other members and was wounded himself, according to investigators.

More recently, he recruited Thomas, 25, another disgruntled member of the gang, a man who suburban prosecutors once said “can’t stop selling weed, heroin, crack cocaine, and assaulting people.” Thomas had been paroled in September 2018, about halfway through a maximum three-year sentence that could have kept him in prison until next March, state records show.

Law enforcement sources on Thursday provided these details about what Perez and Thomas did in the moments leading up to the fatal shooting of Nikolette:

On Sunday afternoon, the two walked onto Clearfield armed with a handgun and an AK-47, and made their move to take the corner.

First, they shot at a black SUV they suspected of carried gang members. Shooting wildly with the AK-47, Thomas narrowly missed passersby, including an 11-year-old girl unloading groceries from a car.

Next, they turned their attention to a 53-year-old man in a wheelchair who witnessed the shooting and who they felt had looked at them the wrong way. The man pulled out a gun, which he was licensed to carry, but did not shoot because the two ran away.

Then Perez and Thomas sped in a car to nearby Water Street and the home of Nikolai Rivera, whom sources identified as a higher-up in the Clearfield gang. Like the two men accused of killing his daughter, Rivera has a long history of gun and drug offenses, starting when he was a juvenile, court records show.

Rivera wasn’t home. But his 2-year-old daughter was, along with her mother, Joan Ortiz, three other children, and a contractor who had just stopped by to clean the carpeting.

Perez and Thomas saw the contractor in the doorway, mistook him for Rivera, and opened fire.

The carpet cleaner was hit once in the stomach and collapsed, police said. Ortiz, holding her daughter, was struck in her upper left arm. A bullet hit Nikolette in the back of her head. She died minutes later.

» READ MORE: Philly’s weekend shootings show a tragic reality: The littlest victims suffer most

Perez fled to Chester, where he was taken into custody on Tuesday. Thomas didn’t travel as far. He hid at a friend’s house in North Philadelphia, where police picked him up late Wednesday on a probation violation.

Under questioning by homicide detectives, Thomas confessed to firing the shot that killed Nikolette, sources said. He had not been formally charged as of Thursday afternoon, but was expected to be charged with murder and related offenses.

At a hearing early Thursday, Perez was ordered held without bail on dozens of charges, including one count of murder and nine counts of attempted murder.

» READ MORE: Residents, Philly officials lament weekend violence after 2 children are shot in 24 hours

e.

Both men have extensive criminal records for drug dealing and other crimes.

Perez has a long history of drug-related convictions, and in 2017 was sentenced to 10 years probation after being found guilty of drug dealing, according to court records.

He was sentenced to three to six years behind bars in 2011 after pleading guilty to similar offenses, records show. And in 2010, he pleaded guilty to several drug-related crimes committed in 2007 and 2009, the records show, and was sentenced to five years probation.

Thomas’ record includes seven convictions since age 18, for crimes ranging from a robbery in Norristown to drug dealing and making terroristic threats in Philadelphia. Court records show repeated arrests for dealing crack cocaine, heroin, and marijuana in the area around Clearfield.

He has been imprisoned repeatedly, according to investigators. During one stint in jail, court records say, the then-20-year-old Thomas threatened a prison guard, telling her he would arrange to have her attacked on the street.

Thomas’ latest case was a 2016 arrest in Philadelphia on charges of dealing drugs and possession of marijuana. He pleaded guilty to dealing and was sentenced to serve 11½ to 23 months in jail. The marijuana charge was dropped.

His record in Montgomery County started in 2010, when he was arrested as a juvenile under an alias, Devontal Thomas, and was charged with simple assault and harassment. Three years later, he was arrested again for robbery after punching another teen in the face at a church carnival in Norristown and stealing his iPod. He was later convicted.

During a 2017 hearing in Montgomery County for his third violation of probation in the 2013 assault, his attorney said he “had a troubled upbringing” and had shown early signs of mental health issues, including attempts to kill a cat as a child, a transcript of the hearing shows.

His attorney, George M. Griffith Jr., contended that Thomas needed treatment for those issues and for persistent drug use.

Montgomery County Assistant District Attorney Bridget Gallagher disputed that characterization, saying, "We’re not talking about some drug addict who needs to just go into inpatient treatment.”

She said Thomas, who never had a real job and paid his bills by selling drugs, was driven by “anger and the desire to make money.” His goal, she said, was to stay out of jail, “not to change his life.”

Judge Joseph Walsh said Thomas had shown “very little remorse and accepted minimal responsibility for his actions.” He ordered Thomas back to prison on the original charge, imposing a minimum term of 18 months and a maximum of three years.

Serving the full three years would have kept Thomas behind bars until March 27, 2020. But last year, the state Board of Probation and Parole approved his release after18 months, citing his “positive institutional behavior” and his “demonstrated motivation for success.”

Thomas was freed Sept. 27, 2018, and put on supervised parole.. He was forbidden to possess ammunition or associate with people who use or sell drugs.

A funeral service for Nikolette Rivera will be held at 7 p.m. Wednesday, Oct. 30, with viewings from 5 p.m. until the service Wednesday and from 8:30 to 9:30 a.m. Thursday, Oct. 31, at Batchelor Bros. Funeral Services, 7112 N. Broad St. Burial will be in Greenmount Cemetery.