
6 P.3d 1129 (2000)
2000 UT 61
Lloyd G. JONES and Rose J. Jones, trustees of the KKAMMS Trust; Wayne H. Jones and Elma W. Jones, trustees of the KLABDS Trust; Quinn Chamberlain, an individual; and Sylvia J. Chamberlain, an individual, Plaintiffs and Appellants,
v.
ERA BROKERS CONSOLIDATED, a Utah corporation; Scholzen Products Company, Inc., a Utah corporation; Interstate Rock Products, a Utah corporation; Bilt Rite Construction, Inc., d/b/a All Vinyl Fencing, a dissolved Utah corporation; and John Does 1-10, Defendants and Appellees.
No. 981771.
Supreme Court of Utah.
August 4, 2000.
V. Lowry Snow, Lewis P. Reece, Duane L. Ostler, St. George, for plaintiffs.
Ronald W. Thompson, Stephen H. Urguhart, St. George, for defendants.
HOWE, Chief Justice:

INTRODUCTION
¶ 1 Plaintiffs Lloyd G. Jones and Rose J. Jones, trustees of the KKAMMS Trust; Wayne H. Jones and Elma W. Jones, trustees of the KLABDS Trust; Quinn Chamberlain; and Sylvia J. Chamberlain (collectively the Joneses) appeal from the trial court's grant of summary judgment in favor of defendant Interstate Rock Products, Inc. (IRP). The Joneses contend that the trial court erred in awarding IRP approximately $107,000 of the surplus proceeds from a nonjudicial foreclosure sale made pursuant to Utah Code Ann. § 57-1-29 (Supp.1999).[1]


*1130 BACKGROUND
¶ 2 On March 6, 1996, the Joneses conveyed 240 acres of real property (the property) near Toquerville, Utah, to CFH Development Company, L.C. (CFH) in exchange for a purchase money deed of trust and a trust deed note. The Joneses recorded the deed of trust on March 13, 1996, in Washington County, Utah. Eagle Mortgage Company (Eagle) loaned CFH money to develop the property; again, CFH secured its promissory note by a deed of trust, which Eagle recorded subsequent to the Joneses' deed of trust. As part of the loan agreement between CFH and Eagle, the Joneses signed a subordination agreement wherein they agreed to subordinate their first trust deed position to Eagle, thereby granting Eagle's trust deed first priority. The subordination agreement was also recorded.
¶ 3 CFH apparently intended to develop the property in different phases, and on June 20, 1996, contracted with IRP to construct various improvements on a part of it known as "Cholla Creek, Phase I located in the Town of Toquerville, Utah." IRP began construction on Phase I, but CFH failed to timely pay IRP and incurred a substantial debt to it before the project was completed. In addition, CFH defaulted on its promissory note to Eagle on or about April 11, 1997.
¶ 4 Approximately one month after CFH's default, the parties to the development project (including CFH, the Joneses, Eagle, IRP, and the city of Toquerville) entered a construction agreement wherein IRP agreed to continue work on the project in return for certain assurances of payment.
¶ 5 After the parties entered the construction agreement and before IRP had been fully compensated for work done, Eagle pursued a nonjudicial foreclosure on the property that resulted in a foreclosure sale on December 29, 1997. Upon sale of the property, Eagle's first priority lien was satisfied. The surplus amount of $174,474.65 was then deposited with the clerk of the Fifth District Court pending determination of the person or persons legally entitled to it pursuant to section 57-1-29.
¶ 6 The Joneses filed this action for declaratory relief, contending that inasmuch as Eagle's claim as primary lienholder had been satisfied, the Joneses' claim to the proceeds was now superior to all other creditors. IRP filed a counterclaim for the excess funds, contending that because it was still owed $107,482.78 for work done on the project, IRP was legally entitled to the funds pursuant to the construction agreement. IRP moved for summary judgment on its counterclaim, contending the construction agreement clearly provided that proceeds from the project would be paid to IRP before being paid to the Joneses, even in the event of foreclosure. The Joneses contested IRP's interpretation of the construction agreement, asserting that it simply did not provide for payment to anyone in the event of foreclosure. The trial court granted IRP's motion for summary judgment, finding:
The language of paragraph 1e of the Agreement is not a model of clarity, but the intent of the parties to the Agreement, including [the Joneses], is sufficiently clear on one point: In order to avoid an immediate collapse of CFH's project, IRP would continue work and be assured of being paid for past and future work, if not fully paid from other sources, from the proceeds of sale of the property prior to any disbursement to CFH or [the Joneses] . . . . This Court concludes that [the Joneses' secured] interest and claim to such proceeds were, in part, bargained away and made subject to [their] contractual obligation to IRP, and the Court considers the Agreement to have obligated [the Joneses] to allow IRP to be paid from the surplus proceeds prior to [the Joneses] receiving any disbursement.
¶ 7 The Joneses appeal from the trial court's judgment, contending that the court incorrectly interpreted the construction agreement and thus erred in awarding IRP $107,000 of the surplus proceeds of the foreclosure sale.

STANDARD OF REVIEW
¶ 8 Summary judgment is appropriate only when no genuine issues of material fact exist and the moving party is entitled to *1131 judgment as a matter of law. See Utah R. Civ. P. 56(c); Copper State Leasing Co. v. Blacker Appliance & Furniture Co., 770 P.2d 88, 89 (Utah 1988). We review a trial court's grant of summary judgment for correctness, giving no deference to its conclusions of law. See Plateau Mining Co. v. Utah Div. of State Lands & Forestry, 802 P.2d 720, 725 (Utah 1990).

ANALYSIS
¶ 9 Disposition of the proceeds of a trustee's sale is governed by section 57-1-29 of the Utah Code, which provides in pertinent part that "[t]he trustee shall apply the proceeds. . . first, to the costs and expenses of exercising the power of sale and of the sale. . . second, to payment of the obligation secured by the trust deed, and the balance, if any, to the person or persons legally entitled to the proceeds." Eagle, as the holder of the priority trust deed, appropriately received the first disbursement of the proceeds. The balance was then to be given to "the person or persons legally entitled to the proceeds." Id. The Joneses assert that the trial court erred in determining that "the person or persons" was IRP.
¶ 10 We determined in Randall v. Valley Title, 681 P.2d 219, 221 (Utah 1984), that "[a]lthough § 57-1-29 does not specifically mention junior trust deeds or lienholders, the surplus from the sale stands in the place of the foreclosed real estate and is subject to the same liens and interests that were attached to it." Thus to determine the persons legally entitled to the proceeds of the foreclosure sale as between IRP and the Joneses, we must determine their interests in the property before foreclosure.
¶ 11 Before foreclosure, the Joneses held the second priority position on the property by virtue of their trust deed, subject only to any provisions to the contrary in the parties' construction agreement. IRP's pre-foreclosure interest in the property consists only of those rights bargained for in the construction agreement. Because the Joneses hold a priority interest in the property, IRP is entitled to judgment as a matter of law only if, as the district court found, the Joneses' "[secured] interest and claim to [the] proceeds were, in part, bargained away and made subject to [their] contractual obligation to IRP."
¶ 12 We now review the trial court's interpretation of the contract to determine whether the Joneses did indeed "bargain away" their priority to the proceeds. In our review of the court's decision, "[w]e accord [its] interpretation of [the] contract no deference and review it for correctness." Aquagen Int'l, Inc. v. Calrae Trust, 972 P.2d 411, 413 (Utah 1998); see also Gibbs M. Smith, Inc. v. United States Fidelity & Guar. Co., 949 P.2d 337, 340 (Utah 1997) ("`Questions of contract interpretation not requiring resort to extrinsic evidence are matters of law, and on such questions we accord the trial court's interpretation no presumption of correctness.'") (quoting Zions First Nat'l Bank v. National Am. Title Ins., 749 P.2d 651, 653 (Utah 1988)). We look to the writing itself to ascertain the parties' intentions, and we consider "`[e]ach contract provision . . . in relation to all of the others, with a view toward giving effect to all and ignoring none.'" Plateau Mining Co., 802 P.2d at 725 (quoting Utah Valley Bank v. Tanner, 636 P.2d 1060, 1061-62 (Utah 1981)); see also Willard Pease Oil & Gas Co. v. Pioneer Oil & Gas Co., 899 P.2d 766, 770 (Utah 1995).
¶ 13 The parties' agreement provided IRP several assurances of payment. First, CFH was to release to IRP lots eleven and thirty-two of the proposed subdivision, which IRP would then sell to reduce CFS's indebtedness to IRP. Second, certain monies held in an escrow account were to be disbursed to IRP to further reduce the amount owed. The final assurance, which is contained in paragraph 1(e) of the construction agreement and the meaning of which is contested, provides:
That any other monies owed to IRP after completion of the project not satisfied by proceeds earned from the sale of the entire project, proceeds from the sale of Lot 11 and Lot 32, and the amount paid from Ken's Construction Control shall be paid to IRP upon the sale of each lot by pro rata applying the amount of the lot sale and the amount of money owed by the number of *1132 lots in the subdivision less the two lots IRP will have received, and they will receive a partial payment on each lot out of escrow for the sale on each lot, prior to any disbursement to CFH, or Jones. For example, if there are 58 lots and the remaining amount due is $58,000.00, $1,000.00 plus accrued interest at 10% would be paid on each lot.
(Emphasis added.)
¶ 14 Paragraph five of the construction agreement reaffirms that CFH and the Joneses agreed that any monies still owed to IRP would be paid "from the sale of each lot as set forth herein."
¶ 15 It is IRP's position that because, under the terms of paragraph 1(e), IRP would have received payment from the proceeds of the sale of the lots before the Joneses if the property had not been foreclosed upon, IRP retains the same right to priority payment upon foreclosure according to our decision in Randall. IRP arrives at this conclusion by defining "sale" in paragraph 1(e) as any type of salewhether in the ordinary course of business or through foreclosure. If "sale" refers to any type of sale, including foreclosure, then IRP would indeed be entitled to receive the proceeds of a foreclosure sale "prior to any disbursement to CFH or Jones" as the agreement provides.
¶ 16 However, we disagree with IRP's characterization of the term "sale" and thus the rights bargained for in the agreement. Looking at the terms of the contract as a whole and giving meaning to each provision, as we must do, see Plateau Mining Co., 802 P.2d at 725, it is clear that the parties distinguished a sale in the ordinary course of business from a foreclosure sale. While paragraph 1(e) explains how IRP was to be paid if the property was sold in the ordinary course of business, paragraphs three and four provide how IRP was to be protected in the event of foreclosure on the property:
3. Eagle agrees to forebear filing any notice of default or foreclosure proceedings until after June 12, 1997, so long as IRP completes the construction by June 1, 1997.
4. Eagle agrees to give IRP the first option, prior to foreclosure sale, to purchase their secur[ed] interest in the property developed by CFH known as the Cholla Creek Development for the balance owed by CFH to Eagle at that time consistent with the terms of Eagle's securit[y] agreement.
¶ 17 Not only does the agreement not provide for payment to IRP in the event of foreclosure, but paragraph four clearly shows the parties intended that IRP's interests would be protected upon foreclosure only if it purchased Eagle's secured interest in the property. In other words, the agreement did not grant IRP any rights or interests in the property that survived the foreclosure sale because it did not exercise its option to purchase Eagle's secured interest. Any other interpretation of the contract would make the "option" provision unnecessary. See Dixon v. Pro Image Inc., 1999 UT 89, ¶ 14, 987 P.2d 48 (holding that courts should read a contract as a whole, giving effect to each provision); Nielsen v. O'Reilly, 848 P.2d 664, 665 (Utah 1992) (same).
¶ 18 Such a result may seem unjust. However, as paragraphs three and four of the agreement illustrate, IRP was aware of the possibility of foreclosure and could have protected itself either by ensuring that the contract granted it rights to foreclosure proceeds or by purchasing Eagle's secured interest. We cannot now go back and do for IRP what it failed to do for itself. See Provo City Corp. v. Nielson Scott Co., 603 P.2d 803, 806 (Utah 1979) (holding that a court cannot rewrite an unambiguous contract); see also Rio Algom Corp. v. Jimco Ltd., 618 P.2d 497, 505 (Utah 1980) (holding that a court cannot write for the parties a better contract than they wrote).

CONCLUSION
¶ 19 We hold that the excess proceeds of the foreclosure sale belong to the Joneses. Before the foreclosure, the Joneses held the second priority interest in the property and that interest survived foreclosure. Because the parties' agreement did not provide for payment to IRP before the Joneses in the event of foreclosure, IRP did not own any *1133 interest in the sale proceeds. We reverse the decision of the trial court.
¶ 20 Associate Chief Justice RUSSON, Justice DURHAM, Justice DURRANT, and Justice WILKINS concur in Chief Justice HOWE's opinion.
NOTES
[1]  This section has not been materially altered since its enactment in 1961.
