SECOND AMENDED AND RESTATED THREE-PARTY AGREEMENT