—(1) Where a contract has become impossible of performance or been otherwise frustrated, and the parties thereto have for that reason been discharged from the further performance of the contract, this section shall, subject to section 3, have effect in relation thereto.
(2) All sums paid or payable to any party in pursuance of the contract before the time when the parties were so discharged (referred to in this Act as the time of discharge) shall, in the case of sums so paid, be recoverable from him as money received by him for the use of the party by whom the sums were paid, and, in the case of sums so payable, cease to be so payable:
Provided that, if the party to whom the sums were so paid or payable incurred expenses before the time of discharge in, or for the purpose of, the performance of the contract, the court may, if it considers it just to do so having regard to all the circumstances of the case, allow him to retain or, as the case may be, recover the whole or any part of the sums so paid or payable, not being an amount in excess of the expenses so incurred.
(3) Where any party to the contract has, by reason of anything done by any other party thereto in, or for the purpose of, the performance of the contract, obtained a valuable benefit (other than a payment of money to which subsection (2) applies) before the time of discharge, there shall be recoverable from him by that other party such sum (if any), not exceeding the value of that benefit to the party obtaining it, as the court considers just, having regard to all the circumstances of the case and, in particular —
the amount of any expenses incurred before the time of discharge by the benefited party in, or for the purpose of, the performance of the contract, including any sums paid or payable by him to any other party in pursuance of the contract and retained or recoverable by that party under subsection (2); and
the effect, in relation to that benefit, of the circumstances giving rise to the frustration of the contract.
(4) In estimating, for the purposes of this section, the amount of any expenses incurred by any party to the contract, the court may, without prejudice to the generality of this section, include such sum as appears to be reasonable in respect of overhead expenses and in respect of any work or services performed personally by that party.
(5) In considering whether any sum ought to be recovered or retained under this section by any party to the contract the court shall not take into account any sums which have, by reason of the circumstances giving rise to the frustration of the contract, become payable to that party under any contract of insurance unless there was an obligation to insure imposed by an express term of the frustrated contract or by or under any enactment.
(6) Where any person has assumed obligations under the contract in consideration of the conferring of a benefit by any other party to the contract upon any other person, whether a party to the contract or not, the court may, if in all the circumstances of the case it considers it just to do so, treat for the purposes of subsection (3) any benefit so conferred as a benefit obtained by the person who has assumed the obligations as aforesaid.