What is the version of the following sentence with correct punctuation?

Finally after three months living with the inhabitants at The Edge of the World sharing their ups and downs the pair managed with help from their new friends to repair the aircraft they came in Thus it was that they perhaps the first to do so succeeded in leaving The Edge of the World and returning to Denmark
Finally, after three months living with the inhabitants at The Edge of the World, sharing their ups and downs, the pair managed, with help from their new friends, to repair the aircraft they came in. Thus it was that they, perhaps the first to do so, succeeded in leaving The Edge of the World and returning to Denmark.