In the moments when they feared they were about to die, they reached for their phones.
"ACTIVE SHOOTER," a Marine typed to his girlfriend from a recruiting centre in Chattanooga.
"Love you guys. Was shot," a health inspector wrote from a conference room in San Bernardino.
"Mommy, I love you," a 30-year-old accountant texted from the scene of the largest mass shooting in American history. He was hiding in the bathroom of the nightclub Pulse, in Orlando. "I'm gonna die," Eddie Justice typed.
His mother messaged back; then his texts stopped coming. Her son's final moments would linger on the small glowing screen.
Rarely are people who die so horribly, so unexpectedly, granted the chance to have final words. But now in our pockets are little devices that can connect us quickly and quietly to almost anyone in the world. In the unimaginable moment when we realise our next movements could be our last, we can choose to spend them typing - one final call for help, one last message of love.
These texts, and sometimes social media posts, are a jarring way to learn of a loved one's death - but they can give survivors a kind of closure that a shocking call or knock on the door could never provide. At the same time, these messages force a direct look into the fear and helplessness that filled those last moments, and that, too, can be hard to live with.
"My family is happy that my mom had the opportunity to talk to him and be able to respond to him in that moment," said Lakitra Justice, Eddie's sister. "There are families that didn't get that."
Justice's messages to his mother went viral as the world tried to comprehend why Omar Mateen, a 29-year-old security guard, would enter a gay club to kill 49 people and injure 53 others. (Mateen left his own final message in a call to emergency services, in which he pledged his allegiance to Isis.)
These electronic messages are the most modern versions of a timeless human impulse - the desire for one last moment of connection. In the past they were scrawled on paper, on walls, on anything that could be marked in a moment of catastrophe.
In 1944, poet Miklós Radnóti was executed in Hungary after a brutal forced march by Nazi soldiers, his body piled in a mass grave. A year and a half after he was killed, the grave was exhumed, and poems from the end of his life were found tucked inside his coat. One was addressed to his wife: "When may I see you? I hardly know any longer. . ."
In the agonising minutes while pilots attempted to wrestle a disabled jet over Japan in 1985, a passenger wrote, "I'm scared. I'm scared. I'm scared. Help. I feel sick. I don't want to die."
"The plane is turning around and descending rapidly," wrote one of the other 520 victims of Japan Airlines Flight 123, the deadliest single-plane disaster in history. "I am grateful for the truly happy life I have enjoyed until now."
Those messages weren't received, of course, until after the senders died. Technology changed that.
"I think they've taken over the cockpit. An attendant has been stabbed and someone else up front may have been killed. The plane is making strange moves."
Those were words left by Peter Hanson, who called his father from United Airlines Flight 175 on September 11, 2001.
Another passenger, Brian Sweeney, left a message for his wife on their home answering machine: "If things don't go well, and it's not looking good, I want you to know I absolutely love you."
The recorded calls and voice mails made by the passengers of 9/11 were played on the news, shared online and later appeared in movies. It allowed the world to witness their final moments - and a witness is often exactly what people want most when they know they are about to die, said Maureen Keeley, a professor of communications studies at Texas State University and the co-author of Final Conversations: Helping the Living and the Dying Talk to Each Other.
Keeley has been researching the last words shared between loved ones for 16 years, and she says she's found universal tendencies across all circumstances and cultures. When confronted with death, we feel a strong impulse to communicate - whether to resolve a conflict, to thank a loved one, to share thoughts on faith or spirituality - but in moments of greatest urgency and fear, final messages are often distilled to one simple theme: love.
In this way, she says, technology offers us a profound gift in extraordinary circumstances. "You have no control at the end," she said. "But now we have this little snippet of control over our communication - to know that, at least I got to say goodbye, I got to say 'I love you.' "
As voicemails gave way to text messages, these goodbyes have become easier to send quickly, even in dangerous circumstances. In 2006, a gunman stormed Platte Canyon High School in Bailey, Colorado, to take six girls hostage, then killed himself. Five of the girls survived, but Emily Keyes was shot in the head. Before she died, she texted her father, "I Love U Guys".
Now we have this little snippet of control over our communication - to know that, at least I got to say goodbye, I got to say 'I love you'.
In 2014, as Jeffrey Hunter hid in a bathroom trying to wait out the tornado ravaging Arkansas, the 22-year-old texted, "Goodbye mama."
In some cases, victims of disaster survive - and their messages aren't as final as they seemed.
Julie Swann-Paez, the health inspector in San Bernardino, was shot in the bladder and pelvis when Syed Rizwan Farook and Tashfeen Malik stormed into a room where she and co-workers were enjoying a holiday reception. As she lay on the floor, she wanted her family to know what had happened so that when the news broke, they would look for her in a hospital. She pulled her phone from her pocket: "Love you guys. Was shot".
Swann-Paez would survive, but her family couldn't know that at the time.
"They were scared," she said. "At first they thought, did I write something wrong? Was it an auto-correct? Was I joking? Then when they realised there was a shooting, they panicked."
Her message was echoed by one of the victims of the Orlando shooting, a club performer who goes by Jeff Xcentric Lords. He posted a frantic message on his Facebook page: "I been shot atbclub pulse. . . losiing blood, love u all. . . ." He was reported to be in stable condition.
Swann-Paez said she didn't think she would die, even as she bled on the floor of the conference room. But, just in case, "I wanted to make sure my last words were that I loved them," she said.
When those words are the last, the sense of closure and connection might offer a lasting solace to grieving friends and family, Keeley says. But not everyone will feel that way.
"Technology is a double-edged sword," she said. "For some, uncertainty is better; they think, 'I don't want to know how much they hurt at the end of life. I don't want to know how scared they were, because it's too much to bear.' "
For those people, she says, a lingering Snapchat video, Facebook post or text message will haunt instead of heal.
But that final connection is almost certainly a comfort to the person who sent the message.
"To be able to say 'I'm scared' to somebody, and know that someone is on the other end - you know that someone is holding you, even through a text," she says. "You're not alone."