Crossing in front of an oncoming train is an absolutely stupid thing to do, and the man featured in this video should be counting his lucky stars that both he and his dog are still alive.

This clip was recently filmed in Troy, Montana, and was captured by someone doing what any sane human would do: waiting at the crossing for the train to go past. A man riding an ATV had other ideas.

Watch Also: Chevrolet Tahoe Destroyed By Train After Skipping Boom Gates

As the train quickly approaches and blasts its horn, the man on the ATV nonchalantly rides directly into the rails with his dog walking beside him. While he was able to get through the crossing with roughly a second to spare, there are so many things that could have gone wrong.

For starters, the ATV could have experienced some kind of mechanical issue as it was crossing the tracks or the man could have simply misjudged the timing. Being hit by an oncoming train while in a car often proves to be fatal, so there’s no doubt that had something unforeseen happened, the man (and his dog) would, in all likelihood, have been killed.

Speaking of the dog, it could have easily be scared or agitated while crossing the tracks as the train driver blasted the horn, potentially forcing the ATV rider to slow down or even stop – and that would have been fatal. The man filming the near-miss had an oh-so-appropriate response, saying “What the f**k!” as the man rode his ATV past.