While peering out onto the burning rubble at Ground Zero in the days after September 11, Ray Kelly (then an executive at Bear Stearns) had an epiphany: “The NYPD needs its own intelligence unit.” If the federal government continued to hold a monopoly on nationwide intelligence information, he theorized, the NYPD would simply be “waiting to respond to the next [terrorist] attack” and “helpless to prevent it.” Sworn in as New York City police commissioner just four months later in January 2002, the former Wall Streeter made it his mission to ensure that the NYPD would have the power—and intelligence—to stop something like this from happening on NYC soil again.

Doing so would require the creation of a secret, highly invasive intelligence unit in New York City that would “rival the FBI” and focus on the city in a way that that national organization never could. For this, he’d need the help of David Cohen, a retired CIA officer who had also gone to Wall Street. Together, Kelly and Cohen, whom he appointed as the NYPD’s deputy commissioner for intelligence, launched a top-secret spying unit in New York City—the first of its kind.

To be effective at spotting “homegrown terrorists” and “thwarting their attacks,” the program wanted officers who could delve into the personal lives of innocent citizens in Muslim communities. And delve they did.

In the forthcoming book Enemies Within, AP reporters Matt Apuzzo and Adam Goldman rake through never-before-published NYPD documents and intelligence interviews to find out exactly how much damage this invasive spying unit did to innocent New Yorkers—most of whom were Muslims. The answer, Apuzzo and Goldman found, was a lot.

Below, nine shocking revelations about the NYPD’s top-secret spying unit.

1. The NYPD labeled all Mosques "terrorism centers."

In order to gain access to Muslim houses of worship, NYPD lawyers created a new case category, which they referred to as a “terrorism enterprise investigation” (TEI). Using this terminology, they were able to classify any mosque as a potential terrorist hub, and the worshippers inside as potential suspects. This gave them freedom to record sermons, photograph worshippers, and spy on imams—all in the absence of specific evidence of criminal activity.

“A mosque is different than a church or temple,” one NYPD officer familiar with the effort explained. Since Muslims pray more than once a day at their places of worship, the officer continued, it makes it different than a church. “They pray five times a day ... If something bad is going to happen, they’re going to hear about it all in the mosques.”

2. They hired a CIA operative to feed them classified information and help run the program.

The idea of putting a CIA officer inside a municipal police department had never been tried. But David Cohen knew that in order for a spying program of this caliber to work, he’d need someone who had access to “the latest raw federal intelligence.” That someone was Larry Sanchez, a CIA analyst in between assignments at Langley. After CIA Director George Tenet signed off, Sanchez was given the long-winded title of “CIA director’s counterterrorism liaison to the state of New York.” His actual job, Apuzzo and Goldman reveal, was to be Cohen’s “personal CIA representative.” The unprecedented move bridged a gap between the NYPD and CIA that, in retrospect, should not have been bridged. “NYPD officers are trained to uphold the law,” Apuzzo and Goldman write. “CIA officers are trained to subvert [it].”

3. The NYPD wanted to visit Internet cafes and join gyms to monitor "suspicious activity" in Muslim communities.

After studying the dossiers of the 9/11 hijackers, Cohen and Sanchez became convinced that, if they had “eyes and ears” in the right communities, they’d be able to spot potential terrorists. Much of this came from studying the final moves of Mohamed Atta, one of the ringleaders of 9/11. Atta had traveled the country, attended mosques sporadically, visited Internet cafes, and joined gyms. Activities like this became a “roadmap” for the new spying unit. “If cops had a better handle on ... which Internet cafes were nearby ... or even which gyms a young Middle-Eastern man would attend ... maybe they could piece together the clues. Maybe they could prevent the next 9/11.”

4. They exploited Middle-Eastern-looking men to use as undercover officers.

In order to successfully infiltrate Muslim communities in Brooklyn and Queens, the NYPD needed Middle-Eastern-looking officers who could (and were willing to) blend in. Unlike the CIA, whose new officers were subject to top-secret security clearance, the NYPD had access to a hotbed of middle-class workers, many of whom could speak Arabic. Since the men didn’t have to—officially— take on a different identity, they were not considered undercover by the NYPD. Because they were the ones “raking in the coals,” they were nicknamed “rakers.” (Later, some were referred to as “mosque crawlers”).

5. They sent “rakers” into restaurants, delis, barber shops, and gyms to spy on potential terrorists.

Each day, a set of two rakers (they worked in pairs) would leave the intelligence office and head to different places in Muslim communities across New York City: restaurants, mosques, gyms, Internet cafes, etc. The rakers’ job was not only to “look like any other young man,” but to talk with whomever they met and determine two things: their ethnicity (Pakistani? Moroccan?) and mood (in the NYPD’s terminology this is called “gauging sentiment”). Once they had those nailed down, the rakers would talk to whoever they’d met, buy their products, and connect with them. What were these people talking about? Was Al Jazeera playing on TV? Were they selling fake IDs? Is there a computer, and if so, have they been watching jihadist videos? All of these details would be cataloged in a report that they’d send to Sanchez.

Over time, the rakers were used to target different groups in NYC based on world events. “If there was a car bombing in Lebanon, a Predator drone strike in Pakistan, or a firefight in Afghanistan, the rakers would be in those neighborhoods, gauging sentiment and reporting back.” The NYPD hoped this would stop terrorist activity in its tracks. “If people in a Pakistani barber shop were enraged over a drone attack that killed nearby civilians, it might be a warning sign that retaliation was imminent.”

6. They considered the rakers program highly successful, and christened it the “Demographics Unit.”

The in-depth, individualized reports on each one of New York City’s ethnic neighborhoods allowed Sanchez and Cohen to “visualize the city in a new way”—one they assumed would allow them to quickly zero in on terrorist activity as it was brewing. In just a few years, they’d transformed the NYPD from plain cops to intelligence officers. The “Demographics Unit,” as this program was christened, mapped out the hotspots (such as mosques and cafes) in each community. If young Muslim men were growing radicalized, for example, they’d know where. Or so they thought.

7. They used it to collect files on huge numbers of innocent citizens, hoping to “thwart homegrown terrorists.”

What many of the NYPD officers learned over time was that “raking” didn’t bring any suspicious activity to light. Instead, it led to enormous files of “alleged terrorist activities” that were completely benign. Brooklyn’s Milestone Park, for example, was deemed a “location of concern” for the sole reason that middle-aged Albanian men frequent it during the early afternoon. What are they doing, you ask? “Getting together for a game of chess, backgammon, or just to have a conversation,” the rakers report reads. The clearest proof that the spying unit was a failure, Apuzzo and Goldman detail in the book, is the NYPD’s failure to discover suspected terrorist Najibullah Zazi—considered the “single greatest threat to U.S. security since 9/11.”

8. They got Washington to pay for everything, even though it was illegal.

In order for the NYPD’s men to look like ordinary customers, the Demographics Unit was given thousands of dollars for each member to spend on coffee, pastries, etc. The money, Apuzzo and Goldman explain, came from the government. “The Demographics Unit, like many intel operations, benefited from a little-known White House anti-drug grant that provided millions of dollars for cars and computers.” Over time, one former NYPD officer familiar with the program said, it became clear that some were focusing their investigation on the places “with the best food.” Such as the Kabul Kabob House in Flushing. How’s that taste, Washington?

9. The result: many Muslims in New York City now live in fear.

While the Demographics Unit was renamed the “Zone Assessment Unit” in 2010, it is reportedly still very much the same. Rakers continue to troll through “ethnic neighborhoods,” filing multiple reports about “alleged terrorist activity.” The result is scared citizens. “The Muslim community is marbled by fear and isolation,” Apuzzo and Goldman write in the epilogue. “The NYPD is in their mosques, businesses, and student groups. Worshippers are afraid to congregate. Young men worry that growing beards will attract police attention.”