After being stranded for six days with no food, limited water and a right leg that was shattered in three places, hiker Gregg Hein will have to do a few months of rehabilitation before he’s back on the hiking trails again.

Hein was hiking by himself down the 13,600-foot Mount Goddard, part of California’s Sierra Nevadas, when he accidentally dislodged a boulder. The boulder broke Hein’s right leg in two places and pushed the bone through his skin, leaving him stranded.

Since Hein told friends and family he wouldn’t be back for another two days, he knew he had some waiting ahead of him. “I realized immediately that this could potentially be a life-or-death situation,” Hein told the Fresno Bee.

To stop the bleeding, Hein thought about using a tourniquet, but decided against it because he knew that would eventually lead to amputation. So Hein let the bleeding slow on its own and splinted his leg with his hiking poles, wrapping them with a belt and spare tubular webbing. Hein waited near the edge of a glacier for four days, where he said he drank melted ice water to rehydrate and clean the wound.

Hein then crawled 1,000 feet down the mountain and the half-mile between him and Davis Lake, where he thought he’d have a better chance of being spotted. It was when he started moving toward Davis Lake that he decided to eat “a couple crickets, five moths, some ants and a few water bugs.”

“[The bugs] were not in any way a supplement,” Hein said. “I never felt hungry throughout the whole six-day ordeal. In many ways my brain shut out unnecessary or superfluous things, specifically fear, hunger and, to a large extent, pain.”

On day six of Hein’s ordeal, the search helicopters finally flew overhead. The search party came thanks to Hein’s dad, who had reported Gregg missing two days after he was expected to come home. After initially spending a full day not being seen by two helicopters – which both flew within 100 yards a total of six times – a search-and-rescue helicopter landed just 50 feet from Hein.

As the sun was sinking between the canyon walls, he was finally saved.