Capital Gains Burden on Strawman or me?

A trustworthy recorded a house purchase in his name with the money I gave him and financed the home for me - thus I had a place to live when I otherwise was not credit-worthy. Now I have to sell the house in which I lived for the last year unexpectedly and quickly and it has appreciated significantly - partially due to fix-ups I made and partially due to a crazy market.

All recordings (title) have been in the other person’s name, but I invested the money and I received most of the profits (minus a reasonable bonus for my friends help). I did not plan on the profits, so this whole thing caught me by surprise. I have to relocate because of a new job - and this is one of the conditions under which I am supposed to be able to defer capital gains even if I had more then one primary residence transaction in the last 5 years (if I understand the tax code correctly).

The problem is that my friend’s CPA says my friend will have to pay the capital gains tax. Can I avoid this? Whom does the IRS look at for the capital gains tax? The person who was recorded as owner of a property or the ‘investor’ who gave the money and got the profit?