(1) The sums paid or payable to a party under a contract before the parties were discharged
(a) in the case of sums paid, are recoverable from that party as money received by him or her for the use of the party by whom the sums were paid; and
(b) in the case of sums payable, cease to be payable.
(2) Where before the parties were discharged the party to whom the sums were paid or payable incurred expenses in connection with the performance of the contract, the court where it considers it just to do so having regard to all the circumstances may allow that party to retain or to recover the whole or a part of the sums paid or payable not exceeding the amount of the expenses.
(3) The court in estimating the amount of the expenses under subsection (2) may include a sum that appears to be reasonable in respect of overhead expenses and in respect of work or services performed personally by the party incurring the expenses.
(4) Where before the parties were discharged 1 of them has by reason of anything done by another party in connection with the performance of the contract obtained a valuable benefit other than a payment of money, the court where it considers it just to do so having regard to all the circumstances may allow the other party to recover from the party benefitted the whole or a part of the value of the benefit.
(5) Where a party has assumed an obligation under the contract in consideration of the conferring of a benefit by another party to the contract upon another person whether a party to the contract or not the court, where it considers it just to do so having regard to all the circumstances, may for the purposes of subsection (4) treat a benefit so conferred as a benefit obtained by the party who has assumed the obligation.
(6) In considering whether a sum ought to be recovered or retained under this section by a party to the contract, the court shall not take into account a sum that by reason of the circumstances giving rise to the frustration of the contract has become payable to that party under a contract of insurance, unless there was an obligation to insure imposed by an express term of the frustrated contract or by or under an enactment.
(7) Where the contract contains a provision that upon the true construction of the contract is intended to have effect in the event of circumstances that operate or but for the provision would operate to frustrate the contract or is intended to have effect whether those circumstances arise or not, the court shall give effect to the provision and shall give effect to this section only to the extent that appears to the court to be consistent with the provision.
(8) Where it appears to the court that a part of the contract can be severed properly from the remainder of the contract, being a part wholly performed before the parties were discharged or so performed except for the payment in respect of that part of the contract of sums that are or can be ascertained under the contract, the court shall treat that part of the contract as if it were a separate contract that had not been frustrated and shall treat this section as applicable only to the remainder of the contract.