(1) This section applies if a party to a discharged contract obtained a valuable benefit (other than a payment of money to which section 36 or 37 applies) before the time of discharge because of anything done by another party in or for the purpose of the performance of the contract.
(2) Despite section 36, the benefited party is liable to pay to that other party any amount (not exceeding the value of the benefit obtained) that the court considers just having regard to all the circumstances of the case.
(3) For the purpose of subsection (2), the court may have regard to—
(a) the amount of any expenses the benefited party incurred before the time of discharge in or for the purpose of the performance of the contract, including any amount paid or payable by the benefited party to any other party under the contract and retained or recoverable by that party under section 36 or 37; or
(b) the effect, in relation to the benefit obtained, of the circumstances giving rise to the frustration or avoidance of the contract.
(4) For the purpose of this section, if a party to the contract has assumed obligations under the contract in consideration of the conferral of a benefit by another party to the contract on any other person (whether or not that person is a party to the contract), the court may, if in all the circumstances of the case it considers it just to do so, treat any benefit conferred on that other person as a benefit obtained by the party who has assumed those obligations.