The Army wants you….awake. Since at least WWII, US military scientists have been tinkering with the human brain to keep pilots, soldiers and staff alert despite lack of sleep. Their enemies have as well: The Nazis infamously plied their ranks with methamphetamines (also known as speed).

But how can people stay awake safely (and ethically)? Few substances are as safe as caffeine used daily by 85% of the US population. Researcher Jaques Reifman, who works on high-performance biotechnology software for the US Army, sought to design an algorithm for caffeine-dosing strategies. His research, accepted into the peer-reviewed Journal of Sleep Research, developed software to learn people’s unique physiology and determine how best to counter lack of sleep under any conditions.

The Army’s plan was to develop a tool that prescribes exactly how much caffeine to consume, and when, to achieve optimal performance, Reifman said in an interview.

Caffeine affects everyone differently. Our bodies have unique metabolisms, while sleep patterns alter caffeine’s effects. To account for this, Reifman and his collaborators administered about a dozen brief response time tests, known as a psychomotor vigilance task (PVT), that informed algorithms assessing the optimal caffeine strategy to maximize alertness at precise times.

The researchers sought to improve on caffeine dosing strategies from six previously published experiments. They administered PVTs over two days to assess an individual’s caffeine response profile, and logged their sleeping schedule. The algorithm, the study found, could design caffeine consumption schedules that achieved similar results with 65% less of the substance or enhance performance by up to 64% with comparable amounts.

While not standard issue for today’s soldiers, Reifman said the algorithm is now being assessed with soldiers in training. Civilians may need to wait a bit longer to tailor their own caffeine consumption. While the Army intends to license the technology, the only public option available now is the 2B-Alert website, which is based on related research. Because it doesn’t integrate testing performance, 2B-Alert isn’t personalized. But Reifman hopes the research will ultimately benefit anyone—shift workers, trucker drivers, nurses, doctors—who need to keep going through the night and day.