
251 N.W.2d 650 (1977)
Henry GESS, Individually and d.b.a. Henry Gess Well Company, Appellant,
v.
Michael R. SILL, Respondent.
No. 46676.
Supreme Court of Minnesota.
March 4, 1977.
O. P. Lund, Minneapolis, for appellant.
Leonard, Street & Deinard and Steven D. DeRuyter, Minneapolis, for respondent.
Considered and decided by the court without oral argument.
MacLAUGHLIN, Justice.
Plaintiff, Henry Gess, pursuant to an oral contract with defendant, Michael R. Sill, agreed to install a new well at defendant's residence in Deephaven, Minnesota. Upon completion of the well defendant refused payment. Plaintiff brought this action alleging that defendant owed him $1,305 *651 for the installation of the well, and defendant counterclaimed asserting that the well was of no value to him because, among other things, it had been drilled at the improper location. The trial court found that plaintiff had materially and substantially breached the contract, made no award of damages to plaintiff, and awarded defendant $1,305 on his counterclaim. We affirm as to the breach of contract but reverse and remand on the question of the damages awarded to defendant.
The trial court found that the well as installed by plaintiff was not in accord with the agreement. Contrary to the agreement, the well was drilled approximately 10 feet from defendant's home and about 12 inches from the driveway which passes in front of his residence. Furthermore, contrary to the agreement, the top of the new well extends 18 inches above the ground, is an eyesore, and is a potential cause of injury to persons and vehicles. The trial court also found that the parties had agreed upon the use of new materials in the installation of the well but that plaintiff had in fact used 42 feet of used drop pipe taken from plaintiff's old well and 110 feet of old electrical wiring that had been spliced together in at least 15 places.
The trial court concluded that plaintiff intentionally and knowingly breached the contract and that the deviations in performance were so material that defendant did not receive substantially what he had bargained for. Based upon the foregoing, the trial court awarded nothing to plaintiff and awarded judgment for defendant on his counterclaim "in the amount of $1,305.00, which is the cost of performing the contract as agreed to between the parties * * *."
1. There is sufficient evidence to support the trial court's determination that the well was neither drilled in the proper location nor installed as the parties had agreed. The evidence also supports the trial court's conclusions that plaintiff's installation of the well was "an intentional deviation [from the contract] without approval or knowledge of the defendant," and that the defects and deviations in plaintiff's performance were so material that defendant did not receive substantially what he had bargained for.
In Ylijarvi v. Brockphaler, 213 Minn. 385, 390, 7 N.W.2d 314, 318 (1942), a case involving the drilling of a well, we discussed the contractor's duty of substantial performance in building and construction contracts:
"* * * For present purposes, it is sufficient to say that substantial performance means performance of all the essentials necessary to the full accomplishment of the purposes for which the thing contracted for has been constructed, except for some slight and unintentional defects which can be readily remedied or for which an allowance covering the cost of remedying the same can be made from the contract price. Deviations or lack of performance which are either intentional or so material that the owner does not get substantially that for which he bargained are not permissible."
In the Ylijarvi case we established that a contractor may not recover when he is guilty of a substantial deviation from the contract or when his intentional deviation is so extreme that the owner does not get substantially that for which he bargained. Because the evidence supports the trial court's findings and conclusions, we hold that there was no error in denying recovery to plaintiff.
2. The trial court awarded the contract price of $1,305 to defendant on his counterclaim and denied recovery to plaintiff, with the result that defendant would obtain a new well at no cost. Since defendant has paid plaintiff nothing for the well, this will result in his unjust enrichment.
The applicable rule of damages is found in Restatement, Contracts, § 346, which provides in part:
"(1) For a breach by one who has contracted to construct a specified product, the other party can get judgment for compensatory damages for all unavoidable harm that the builder had reason to foresee when the contract was made, less such part of the contract price as has not been paid and is not still payable * * *."
*652 The comment to Subsection (1a) further explains that "[s]atisfaction for his harm is made either by giving him a sum of money sufficient to produce the physical product contracted for or by giving him the exchange value that that product would have had if it had been constructed." Regardless of the measure of damages used, the owner "must deduct from the amount of loss thus ascertained the amount, if any, remaining unpaid upon the contract price." McCormick, Damages § 168, p. 649. See, generally, Dobbs, Remedies §§ 12.21 and 12.22.
Based upon the facts of this case, defendant is entitled to the sum of money required for installing the well contracted for, plus any reasonably foreseeable consequential damages resulting from the breach.[1] From that amount, however, must be deducted the contract price which defendant was to have paid plaintiff for the nonconforming well. Defendant cannot have his well without paying for it. The correct amount of damages should be ascertained upon remand.
Affirmed in part, and reversed and remanded in part.
NOTES
[1]  An example of permissible consequential damages would be the reasonable expenses incurred in cutting off or otherwise removing the unsightly pipe which protrudes above the ground from the well and in replacing the sod to its former condition. Defendant claims diminution in the value of his residence as a result of the defective installation; however, it is difficult to understand how diminution could occur if a new well were installed and the defective well were effectively removed from sight.
