A man from Maine and two teenagers planned an ISIS-inspired attack on a Shia Muslim mosque near Chicago, newly unsealed court documents revealed on Friday.

The FBI said Xavier Pelkey of Waterville, Maine, and the two teens — one from the Chicago area and one from Kentucky — communicated through Instagram and other chat platforms with plans to meet in Chicago during “spring break.” The teens were not named due to their age.

The teenager in Chicago allegedly told the FBI that the plan was to “enter the Shia mosque and separate the adults from the children, then murder the adults” all in the name of ISIS, according to a court filing.

“If they had not encountered law enforcement at that point, they would continue on to another Shia mosque or Jewish synagogue and execute the same plan. They did not have a plan to escape but rather their plan ended with them being shot by law enforcement,” the FBI said in its filing.

The FBI conducted search warrants in February at the teenagers’ houses in Chicago and in Kentucky.

During those raids, “agents from Chicago FBI seized multiple firearms, including a Remington pump shotgun, swords, knives, a bow and arrows, multiple homemade ISIS flags, and multiple electronic devices from Juvenile #1’s residence,” according to the FBI.

When agents searched Pelkey’s home in February they allegedly found several hand-painted ISIS flags and three homemade explosives that used fireworks and also allegedly had shrapnel.

When an FBI bomb technician broke apart the devices to inspect them “he found that staples, pins and thumb tacks had been inserted among the device components,” according to court papers.

Pelkey has been charged with being in possession of a destructive device that was not properly registered to him.

The details of the alleged plot and some of the images were made public on Friday after investigators had originally requested some of the documents be held under seal while they continued their investigation.

A judge ordered Pelkey held in custody pending trial.

Court papers included photos that allegedly showed hand painted ISIS signs in Pelkey’s home as well as the alleged explosive devices.

Pelkey’s lawyer could not be immediately reached for comment on Friday.

ISIS identifies with Sunni extremists and has long sought to commit genocide against Shiite Muslims, among others.