Cars with infrared sensors, cameras and collaborative connectivity will eventually go a long way toward avoiding collisions, but human drivers will still be a wild card. Now a new algorithm can predict whether they’ll behave at intersections, and could someday prevent crashes and save lives.

Researchers at MIT developed an algorithm that analyzes several several parameters, including a vehicle’s deceleration, its distance from a traffic light and when the light turns red. It can capture a vehicle’s motion in 3-D in less than five milliseconds, according to MIT News. Using this data, it is able to determine which cars are driven by potential violators, those likely to run a red light, and which cars were obeying the law.

Led by Jonathan How, a professor of aeronautics and astronautics at MIT, some MIT undergraduates and grad students tested the algorithm using traffic data at a busy intersection in Christianburg, Va. The state department of transportation had set up several instruments to monitor cars as part of a safety prediction project. The MIT team analyzed more than 15,000 vehicles in this data set, and found the algorithm was able to spot red-light scofflaws 85 percent of the time. That’s about 15 to 20 percent better than existing algorithms, they say. It also generated fewer false positives than other safety-prediction technologies, which could be helpful if it’s ever implemented for human use.

“If you’re too pessimistic, you start reporting there’s a problem when there really isn’t, and then very rapidly, the human’s going to push a button that turns this thing off,” How tells MIT News.

They even tested it using robots, which used it to navigate a busy intersection. Watch a demo below.

The best part: The algorithm works so quickly that it can give drivers plenty of time to react. The team actually found a “sweet spot,” lasting one to two seconds in advance of a potential collision, when the algorithm has the highest accuracy and when a driver could still have enough time to react to a fellow human who is about to do something dangerous. This could conceivably be integrated into future smart cars, perhaps combined with some kind of dashboard or windshield warning system, so that your car will tell you not to go — even if the light is green — when it senses another car is about to run the light.

The research will be published in the journal IEEE Transactions on Intelligent Transportation Systems.

MIT News