NEW YORK (Reuters) - Throughout 2016 and 2017, a rail terminal built to accept crude oil for the largest East Coast refinery often sat idle, with few trains showing up to unload.

FILE PHOTO: The Philadelphia Energy Solutions oil refinery is seen at sunset in front of the Philadelphia skyline in Pennysylvania, U.S., March 24, 2014. REUTERS/David M. Parrott/File Photo

Although little oil flowed, plenty of money did.

Under a deal Philadelphia Energy Solutions (PES) signed in 2015, the refiner paid minimum quarterly payments of $30 million to terminal owner North Yard Logistics LP - even if little crude arrived. Much of that cash, in turn, flowed to the investors that own both PES and North Yard, led by the Carlyle Group, a global private equity firm with $178 billion in assets.

The deal in effect guaranteed lucrative payouts to Carlyle regardless of whether the refinery benefitted from the arrangement. When oil market conditions made the rail shipments unprofitable later that year, the refinery took heavy losses while its investors continued to collect large distributions for two more years.

The rail contract exemplifies the financial demands Carlyle imposed on PES in the years leading up to the refiner’s bankruptcy in January. The Carlyle-led consortium collected at least $594 million in cash distributions from PES before it collapsed, according to a Reuters review of bankruptcy filings. Carlyle paid $175 million in 2012 for its two-thirds stake in the refiner.

(For a graphic detailing how PES went bankrupt, see: tmsnrt.rs/2BzYUW2 )

More than half the distributions to the Carlyle-led investors were financed by loans against PES assets that the refiner now can’t pay back, the filings show. The rest came from the refiner’s operating budget and payments PES made under the terminal deal to North Yard, a firm with no offices or employees that PES spun off in 2015.

PES has blamed its bankruptcy on environmental regulations that require all U.S. refiners to cover the costs of blending corn-based ethanol into the nation’s gasoline. But the ill-fated train terminal deal and other large payouts to investors played key roles in the refiner’s collapse, according to filings and five current or former PES employees who were involved in the refinery’s decision-making. The employees spoke to Reuters on condition of anonymity.

The investor payouts, along with a slump in refining economics, left PES unable to cover its obligations under the decade-old U.S. Renewable Fuel Standard or the loans it took to finance the distributions to Carlyle, the filings show.

PES had $600 million in debt and $43 million in cash on hand when it filed bankruptcy last month. It now hopes to restructure and continue operations, which employ about 1,100 people.

Carlyle Group spokesman Christopher Ullman declined to comment on whether the distributions or the rail-terminal deal contributed to the refiner’s bankruptcy. PES spokeswoman Cherice Corley defended the payments to Carlyle and said the biofuels regulations played a “significant” role its collapse.

“We feel our capital structure was appropriate, and any suggestion that it was the cause of our restructuring is completely ignoring the significant effect of the flawed Renewable Fuel Standard (RFS),” Corley said.

Other refiners and Pennsylvania officials have also blamed biofuels regulation for the South Philadelphia refinery’s failure, triggering renewed debate about the program on Capitol Hill.

Refiners without the necessary blending facilities, such as PES, are required to purchase regulatory credits, known as RINs, from firms that do such blending. The cost of compliance for PES rose from $13 million in 2012 to $218 million in 2017 as prices increased for the credits, which are traded in an open market.

The refiner, however, failed to pay a large portion of that obligation. In addition to its conventional debt, PES still owes the U.S. Environmental Protection Agency (EPA) regulatory credits worth about $350 million, an amount tied to the fuel it produced over the past two years, according to filings. The firm stopped buying RINs last year - and instead sold them to other refiners for what likely amounted to tens of millions of dollars, Reuters reported in November.

The corn and ethanol lobby has pushed back on the argument that biofuels regulation sunk PES, pointing out that other refiners governed by the same law are raking in their highest profits in years. The refinery’s failure had more to do with the hefty profits it paid to Carlyle as its cash reserves dwindled and its debt soared, said Brooke Coleman, head of the Advanced Biofuels Council.

“The Carlyle Group looks more like a corporate raider than a savior in this deal,” Coleman said.

Carlyle would not lose any of its gains on the PES investment under the refiner’s proposed restructuring plan, which has the support of almost all creditors, according to filings. PES also asks the bankruptcy court to entirely absolve its $350 million obligation to the EPA.

EPA spokeswoman Liz Bowman declined to comment on the delinquent PES credit obligations, citing the bankruptcy proceedings.

CARLYLE RECOUPED INVESTMENT WITH DEBT

Carlyle bought its stake in PES as many other East Coast refineries were closing down because of weak margins. The previous owner, Sunoco - now Energy Transfer Partners ETP.N - contributed the refinery’s assets and became a non-controlling partner.

The $175 million Carlyle paid was its only investment in PES, filings show, and the firm soon recouped its acquisition costs through a loan against the refinery.

At the direction of its investor-controlled board, PES borrowed $550 million in March 2013 and paid $200 million of that to investors, according to bankruptcy filings.

PES then spent $100 million building the rail terminal that year and $30 million in 2014 to double its capacity. At the time, U.S. oil production was skyrocketing as improved drilling technology unlocked new reserves in places such as North Dakota. Carlyle saw an opportunity to tap this cheaper supply and wean PES off costly imports.

The plan worked well at first, in 2013 and 2014, and PES posted earnings of about $500 million for the two years combined.

In January 2015, PES spun off the terminal, creating North Yard as a separate firm. PES then signed a ten-year agreement with North Yard to pay $1.95 for each barrel unloaded and agreed to a minimum quarterly volume of 170,000 bpd, guaranteeing the $30 million quarterly payments to North Yard. For any barrel PES unloaded above the threshold, the refinery paid North Yard 51 cents.

The system was designed to reward PES for success, but had no contingency plan to protect the refiner against the failure that would quickly follow the deal. The rail terminal has averaged just 58,000 bpd since the contract was signed, according to figures provided to Reuters by energy intelligence service Genscape, because Carlyle and PES could no longer access crude at prices low enough to make the rail shipments profitable.

That left PES paying millions of dollars to Carlyle, through North Yard, for oil shipments it never received.

BAD BET ON CHEAP CRUDE

Carlyle’s purchase of PES and the rail terminal investment were bets that U.S. oil would remain cheap relative to imports. A glut of domestic production had caused U.S. crude to sell at a deep discount to imported barrels, with the gap averaging about $8.60 between 2012 and 2015.

But by late 2015, an oil price rebound slashed the domestic discount to less than $3 a barrel – not enough to cover the cost of a long rail journey.

PES nonetheless continued to pay North Yard a total of $298 million between 2015 until August 2017, filings show. The Carlyle-led investor group received $151 million, in eight distributions, of the total paid to North Yard.

In November of that year, PES took on more debt to finance more payouts to investors, borrowing a total of $160 million in two loans against the rail terminal and delivering the proceeds its Carlyle-led backers, filings show.

Corley, the PES spokeswoman said terminal investment more than paid for itself during its more profitable period. But for last two years, PES said in filings, the refinery remained largely cut off from the cheap crude it needed to survive.

“Perversely, it became cheaper to transport crude oil from North Dakota to points in Western Europe than it was to transport the same crude oil to Philadelphia,” the firm said.