Homicidal madmen don’t have much of a capacity for gratitude, but if they did, they’d offer a word of thanks to Charles Whitman. Whitman was the 25-year-old engineering student and former Marine who, in 1966, killed 17 people and wounded 32 in a mass shooting at the University of Texas, before being shot and killed himself by police. Earlier that day, he also murdered his wife and mother. Criminal investigators looking for a reason for the rampage got what seemed to be their answer quickly, in the form of a suicide note Whitman left at his home:

I do not really understand myself these days. I am supposed to be an average reasonable and intelligent young man. However, lately (I cannot recall when it started) I have been a victim of many unusual and irrational thoughts … please pay off my debts [and] donate the rest anonymously to a mental-health foundation. Maybe research can prevent further tragedies of this type.

Whitman got his wish — after a fashion. With the approval of his family, an autopsy was conducted and investigators found both a tumor and a vascular malformation pressing against his amygdala, the small and primitive region of the brain that controls emotion. A state commission of inquiry concluded that the tumor might have contributed to the shootings, earning Whitman a tiny measure of posthumous redemption — and providing all killers since at least the fig-leaf defense that something similar might be wrong with them too.

For as long as evil has existed, people have wondered about its source, and you don’t have to be too much of a scientific reductionist to conclude that the first place to look is the brain. There’s not a thing you’ve ever done, thought or felt in your life that isn’t ultimately traceable to a particular webwork of nerve cells firing in a particular way, allowing the machine that is you to function as it does. So if the machine is busted — if the operating system in your head fires in crazy ways — are you fully responsible for the behavior that follows?

That’s a question that has a lot more than just philosophical implications. No sooner were the Tsarnaev brothers identified as the Boston Marathon bombers than speculation arose as to whether the behavior of older-brother Tamerlan might have been influenced by brain damage sustained during his years as a boxer. The answer was almost certainly no: sports-related brain injury usually leads to volatile and impulsive behavior in people his age, and the bombing was coldly and painstakingly planned. (This was made especially clear by the later revelation that the brothers had originally planned their attack for July 4, but by working hard and applying themselves, they completed their bombs earlier than planned — an illustration of perverse diligence if ever there was one.) But the medical histories of uncounted other killers and violent offenders are filled with diagnoses of all manner of brain diseases and traumas, raising both the issue of whether the perps were truly, fully, responsible for their crimes, and the possibility that the acts could have been prevented in the first place if the illnesses had been treated.

“I don’t think there’s any kind of neurological condition that’s 100% predictive,” says neuroscientist Michael Koenigs of the University of Madison-Wisconsin. “But even when psychopaths know that what they’re doing is a crime, that doesn’t mean they’re in control of their behavior when they offend.”

Even before Whitman made it into the medical texts, scientists were already familiar with the case of Phineas Gage, the 25-year-old railroad worker who, in 1848, was helping to blast a path for a new rail line in Vermont when an errant explosion drove an iron rod into the top of his head, through his left frontal lobe and out his cheekbone. Gage, incredibly, didn’t die and nor did he even exhibit much loss of function. But after the bar was removed, there was a sudden change in his personality. Always a peaceable man, he become volatile, combative and, after a lifetime of polite speaking, wildly profane. It was science’s first glimpse at the seemingly direct cause-and-effect connection between trauma to the brain and the very essence of personality. As our ability to image and repair the brain has improved, we’ve been able to detect far less obvious damage than a railroad spike through the skull — damage that nonetheless has every bit as great an effect.

In a celebrated 2003 case published in the Archives of Neurology, for example, a 40-year-old Virginia schoolteacher with no history of pedophilia developed a sudden interest in child pornography and began making sexual overtures to his stepdaughter. His wife reported his behavior, and he was arrested and assigned to a 12-step program for sex offenders. He flunked out of the course — he couldn’t stop propositioning staff members — and was sentenced to prison. Only a day before he was set to surrender, however, he appeared in a local emergency room with an explosive headache and a range of other neurological symptoms. Doctors scanned his brain and found a tumor the size of an egg in the right orbitofrontal cortex, the region that processes decisionmaking and other so-called executive functions. The tumor was removed and the compulsive sexuality vanished along with it. Less than a year later, the tumor returned — and so, almost in lockstep, did his urges.

“There’s no one spot in the brain for pedophilia,” says Stephen J. Morse, professor of both law and psychiatry at the University of Pennsylvania. “But damage to the orbitofrontal region is known to be associated with disinhibition. We know that various forms of brain damage can contribute to difficulties in being guided by reason.”

Other, more recent studies are finding roots of criminality in other parts of the brain. As Maia Szalavitz reported in April, a team of researchers led by Kent Kiehl, associate professor of psychology at the University of New Mexico, published a study in the Proceedings of the National Academy of Sciences in which the brains of 96 male felons sentenced to at least a year in jail for crimes including robbery, drug dealing and assault were scanned in a functional magnetic resonance imager (fMRI). While they were in the fMRI, the men performed a task that required them to hit a key on a computer when they saw the letter X on a screen, but refrain when they saw the letter K. Since the X appeared 84% of the time and since the two letters look awfully similar to begin with, it was easy to get into the habit of overclicking. The ability to avoid hitting the key too much calls for a measure of impulse control, a faculty processed in a region of the brain known as the anterior cingulate cortex (ACC). The inmates who did worse on the test turned out to have lower levels of activity in the ACC; the ones who performed better had higher levels. Kiehl tracked all of the inmates for four years after their release from prison and found that those with the sleepy ACCs were also more than four times likelier to be rearrested than the others. If you can’t control your impulse to click, the study suggested, you might have equal difficulty controlling the impulse to run afoul of the law.

“There are more papers coming out that show how MRIs predict who reoffends,” said Kiehl in a follow-up e-mail with TIME. “We are examining treatments that increase activity in the anterior cingulate. The goal is to see if we can help identify the best therapies to reduce recidivism.”

Koenigs, who has collaborated with Kiehl, has conducted other work with inmates linking both the amygdala and a region known as the ventromedial prefrontal cortex as possible accomplices in crime. The amygdala is the wild child of that pair, the brain’s seat of fear, suspicion, anger and more. Those are not always bad emotions, provided the ventromedial is able to do one of its assigned jobs, which is to keep the amygdala on a short leash. Working with the Wisconsin Department of Corrections, Koenigs was given access to two groups of volunteer prisoners at a medium-security facility: one diagnosed as psychopathic, one nonpsychopathic.

In the first of two tests, Koenigs scanned the men’s brains with a diffusion tensor imager, a type of MRI that detects how water molecules interact with tissue. In this case, he was trying to determine the soundness of the white matter — the fatty insulation — that protects the neural circuits connecting the ventromedial and the amygdala. In a second test, he used an fMRI to study more directly how clearly the two regions were communicating. In both cases, the brains of the psychopaths were in worse shape than those of the nonpsychopaths, with less robust white-matter insulation and the nerves beneath it doing a poorer job of transmitting signals.

“You can use the findings of this study as a proxy for the connectedness between these two structures,” Koenigs says. “The remorselessness and violence seen in psychopaths may be attributable to the regions not communicating effectively.”

Other studies make a similar case for the mechanistic roots of crime. Enzymes known as monoamine oxidases (MAO) are essential to keeping human behavior in check, breaking down neurotransmitters such as serotonin and dopamine and ensuring that the brain remains in chemical balance. Babies born with a defect in an MAO-related gene — known colloquially as the warrior gene — have been shown to be at nine times higher risk of exhibiting antisocial behavior later in life. Adrian Raine, professor of criminology at the University of Pennsylvania, has found that infants under 6 months old who have a brain structure known as a cavum septum pellucidum — a small gap in a forward region between the left and right hemispheres — are similarly likelier to develop behavioral disorders, and face a higher risk of arrest and conviction as adults as well.

All of this makes the case for a neurological role in many violent crimes hard to deny, but all of it raises a powerful question too: So what? For one thing, brain anomalies are only part of the criminal puzzle. A rotten MAO gene indeed may play a role in later-life criminality, but in most cases it’s only when children have also been exposed to abuse or some other kind of childhood trauma. A child with a stable background and bad genetics may handle his warrior impulses just fine. Koenigs may have found cross-talk problems between the ventromedial and the amygdalae of psychopaths, but he also acknowledges that he didn’t get a look at the men’s brains until they were, on average, 30 years old, and a lot could have gone on in that time. “They’ve had a lifetime of poor socialization, drugs, alcohol, they’ve had their bell rung,” he says. “You don’t know what causes what.”

Even the case of the pedophile schoolteacher, whose pathology switched cleanly off and cleanly on depending on the presence of his tumor, was less clear than it seems. “He touched his stepdaughter only when his wife was not around, and his wife and co-workers had not noticed any problems,” says Morse. “Clearly he had some control or some rational capacity. You can’t say that just because the tumor caused him to have pedophiliac desires, he wasn’t responsible.”

That’s the zone in which science and the law always collide — the causation question that can’t simply be brain-scanned or tissue-sampled or longitudinally tested away. People like Morse believe where once we attributed all crime to moral laxity or simple evil, we’ve now overcorrected, too often looking to excuse criminal behavior medically. “I call it the fundamental psycholegal error,” he says. “The belief that if you discover a cause you’ve mitigated or excused responsibility. If you have a bank robber who can show that he commits crimes only when he’s in a hypomanic state, that does not mean he deserves excuse or mitigation.”

Koenigs takes a more forgiving view: “I’ve been part of a Department of Justice project to help inform judges about how to assess culpability,” he says. “The legal system currently goes about it the wrong way, relying on whether criminals know right from wrong. Maybe they do, but the kinds of things that would then give most people pause just don’t register on some of them.”

Where the two camps do agree is on the need to keep society safe from the predations of people whose raging brains — no matter the cause — lead to so much death and suffering. Here legal theory yields a little more easily to hard science. Scanning every inmate’s ACC before making parole decisions will surely raise privacy issues, but if the science can be proven and perfected, isn’t there a strong case for trying it — especially if, as Kiehl suggests, it might lead to therapeutic and rehabilitative strategies? Babies taken from abusive parents might similarly be scanned as part of a routine medical check, just in case a telltale gap in the brain hemispheres could exacerbate the trauma they’ve already endured, making therapeutic intervention all the more important.

Evil is far too complex and far too woven into our natures for us to think that we can always adjudicate it fairly. But the better we can understand the brains that are home to such ugliness, the more effectively we can contain it, control it and punish it. Now and then, with the help of science, we may even be able to snuff it out altogether.