Prior research has shown older adults with diabetes have a higher risk of developing dementia, but a new study finds that a frequently prescribed diabetes drug could reduce that risk.

Researchers from the German Center for Neurodegenerative Diseases found that diabetics were less likely to develop dementia if they were treated with pioglitazone. The medication is used in short-term and long-term treatment of diabetics whose bodies are still able to produce insulin. Researchers found a correlation between dosage duration and dementia risk. Results were most favorable among patients taking the drug for two or more years.

The study analyzed data from 145,000 men and women age 60 and older, and found that after taking pioglitazone the risk of developing dementia was around 47% lower than in non-diabetics. Metformin, another popular diabetes medication, was also found to lower the risk of dementia, but not as significantly as pioglitazone.

Researchers speculated that pioglitazone’s ability to protect nerve cells may also help reduce dementia risk, but they remain unsure of how the process actually works.