
812 S.W.2d 154 (1991)
Phyllis RANIER, Movant,
v.
MOUNT STERLING NATIONAL BANK, Respondent.
No. 90-SC-196-DG.
Supreme Court of Kentucky.
June 6, 1991.
Rehearing Denied August 29, 1991.
*155 Tom H. Pierce, Versailles, for movant.
John C. Fogle, Mount Sterling, for respondent.
SPAIN, Justice.
This action arises out of the interpretation of a subordination agreement. In 1977, Phyllis Ranier loaned $200,000 to Algin and Doris Nolan and secured the promissory note with a first mortgage lien on their house and lot located in Montgomery County, Kentucky. In 1983, the Nolans applied for a home improvement loan with the Mount Sterling National Bank (Bank) to repair their home which was damaged by fire. Before approving the loan, the Bank required Mrs. Ranier to subordinate her lien on the Nolan property to the Bank's mortgage lien.
On February 28, 1983, Mrs. Ranier and the Bank executed a subordination agreement. The agreement, drafted by the Nolans' attorney, stated in pertinent part as follows:
WHEREAS, Doris C. Nolan and Algin H. Nolan have entered into a loan agreement with the Mt. Sterling National Bank, Mr. Sterling, Kentucky, whereby they will borrow the total sum of $125,000.00 from the Mt. Sterling National Bank, to be secured by a first real estate mortgage on the above described property in favor of the Mt. Sterling National Bank, and it is intended by the parties hereto that the above referenced real estate mortgage lien in favor of Thelma Phyllis Ranier ... shall become a second and junior mortgage lien to the new first real estate mortgage lien in favor of Mt. Sterling National Bank. (Emphasis added.)
The Nolans then executed a six-month promissory note on March 8, 1983, in favor of the Bank in the amount of $125,000 and secured the note with a first mortgage lien on the Nolan property. The future advance clause of the mortgage stated that "... the total indebtedness at any one time outstanding shall not exceed the sum of. . . $125,000 . . ."
Without notice to Mrs. Ranier, the Bank, in July 1985, approved an additional loan to the Nolans in the amount of $75,000 to complete the repairs on their property. The Nolans signed a new promissory note in favor of the Bank in the amount of $200,000. The Nolans' original note in the amount of $125,000 was marked "renewed" by the Bank and returned to the Nolans. The note remained secured only to the extent of the Bank's first mortgage on the Nolan property. The record indicates that the note was renewed several times and a total sum of $95,269.04, including $17,182.82 in principal and $78,269.32 in interest, had been paid to the Bank. The Bank applied the principal and interest to the unsecured portion of the note.
The Nolans defaulted on their notes. A foreclosure action was instituted by the Bank and the Nolan property was sold by the Master Commissioner for $181,000. Both the Bank and Ranier moved for summary judgment on the issue of their respective priorities in the proceeds of the foreclosure sale. The trial court granted summary judgment in favor of the Bank on the issue of priority and awarded it the sum of $140,216.48, which included the original promissory note principal amount of $125,000, plus interest, court costs, and attorney's fees. Mrs. Ranier received the balance of $35,892.09.
Ranier appealed to the Court of Appeals which affirmed the decision of the trial court. We granted discretionary review. Movant Ranier argues that the Bank breached the terms of the subordination agreement when it loaned the additional sum of $75,000. She also argues that Louisville Joint Stock Land Bank v. McNeely, 267 Ky. 425, 102 S.W.2d 389 (1937) requires the Bank to apply the mortgage payments it received from the Nolans first to the original indebtedness or secured portion of its renewed promissory note.
The Court of Appeals held that the equitable principles in McNeely were inapplicable and that the terms of the subordination agreement governed the Bank's priority. *156 The Court of Appeals and the trial court stated that the agreement did not contain any provision which prohibited the Bank from making additional loans to the Nolans nor any requirement that the payments made by the Nolans be applied to the original secured portion of the note.
We agree with the lower courts that the subordination agreement does not contain any provision which prohibited additional loans from the Bank to the Nolans, nor does it provide specifically that any payments received from the Nolans would be used first to the reduce the original secured portion of the renewed promissory note. The Bank did not breach the subordination agreement when it renewed the note and approved an additional unsecured loan in the amount of $75,000 to complete the repairs on the Nolan residence. But we do believe that the Bank has breached its implied covenant of good faith and fair dealing when it failed to give notice to Mrs. Ranier of its subsequent loan to the Nolans and when it unilaterally applied the mortgage payments it received from the Nolans first to the unsecured portion of the new promissory note.
KRS 355.9-316 provides that subordination agreements may be entered into "by any person entitled to priority." In construing contracts, including subordination agreements, we are required to look to the intention of the parties and to ascertain how they meant the agreement to operate when they entered into it. Wilcox v. Wilcox, Ky., 406 S.W.2d 152, 153 (1966); Parrish v. Newbury, Ky., 279 S.W.2d 229 (1955); Jones v. Linkes, Ky., 267 S.W.2d 936 (1954). But "[w]hen a contract is silent with respect to a matter vital to the rights of the parties, a court, in construing it, is necessarily compelled to resort to a consideration of the surrounding circumstances and the conduct of the participants indicating their interpretations." Caudill v. City of Maysville, 297 Ky. 78, 178 S.W.2d 945, 946 (1944).
Prior to the parties entering into the subordination agreement, Mrs. Ranier held a first mortgage position on the Nolan property. She was asked by the Bank and the Nolans to subordinate her advantageous security position in favor of the Bank so that the Bank would approve a $125,000 home improvement loan to the Nolans. Mrs. Ranier then acquiesced and entered into the subordination agreement in the good faith belief that her mortgage would be subordinated only to the extent of $125,000, on which the Nolans were making regular payments. The Bank then loaned the Nolans an additional $75,000. No notice was given to Mrs. Ranier, nor did she agree to further subordinate her mortgage to an additional $75,000. The renewed note in the amount of $200,000 was, in fact, two notes containing a $125,000 secured note and a $75,000 unsecured note. The Bank clearly benefited from the subordination agreement because it was able to obtain a first lien on the property and then it subverted the agreement by applying the payments it received from the Nolans, not to the $125,000 debt, but to the unsecured portion of the note. Mrs. Ranier has been relegated, to her detriment, to an inferior position in the proceeds of the foreclosure sale while the Bank has been allowed to collect on both its unsecured and secured notes, including interest, court costs, and attorney fees. We do not believe that the intent of Ranier when she entered into the agreement was to place her pre-existing first mortgage in the status of a second mortgage in perpetuity. Her intent clearly was that her mortgage be temporarily subordinated to the Bank's mortgage to the extent of $125,000. We believe that the Bank had an implied duty to Mrs. Ranier under the subordination agreement to apply the payments it received from the Nolans in a manner which did not prejudice the priority of her mortgage.
In every contract, there is an implied covenant of good faith and fair dealing. 17A Am Jur2d Contracts section 380; KRS 355.1-203. Indeed, it may be said that contracts impose on the parties thereto a duty to do everything necessary to carry them out. Beech Creek Coal Co. v. Jones, Ky., 262 S.W.2d 174 (1953). The Bank, in this case, has breached its implied duty of good faith and fair dealing when it applied the $95,269.04 which it received from the Nolans in payment first to the unsecured note. Basic fundamental fairness and equity *157 both require the Bank to apply the $95,269.04 to the principal and interest on the original $125,000 secured note.
We recognize the rule that, as between the two of them, a creditor receiving payments from his debtor, without any direction as to their application, may apply them to any legal debt, secured or unsecured, which he holds against his debtor. Straub v. Chemical Bank, Ky.App., 608 S.W.2d 71 (1980). But where a third-party creditor executes a subordination agreement in favor of said creditor, the latter has an implied duty under equitable principles to apply the payment it receives from the debtor in a manner which does not prejudice the third-party creditor's subordinated security interest.
In McNeely, supra, 102 S.W.2d at 392, we stated that
... where neither debtor nor creditor has applied the payment made, the court, in making the application, should exercise a sound discretion according to equitable principles so as to effectuate justice according to the equities of the case. (Citation omitted.) This rule is particularly applicable where the equities of a third person are involved. In such cases the court will apply the payments as may seem reasonable and just according to the rights of all parties involved. (Citations omitted.)
Equity requires the Bank to effectuate justice according to the understanding of the parties as represented by the subordination agreement. That being so, equity recognizes as done that which ought to be done, and the judgment has the practical effect of conforming it. Bowen v. Frazier, Ky., 444 S.W.2d 728 (1969).
The decisions of the Court of Appeals and Montgomery Circuit Court are reversed and the matter is remanded to the trial court. The proceeds of the foreclosure sale shall be distributed in accordance with this decision.
STEPHENS, C.J., and COMBS, LAMBERT, LEIBSON and REYNOLDS, JJ., concur.
WINTERSHEIMER, J., dissents by separate opinion.
WINTERSHEIMER, Justice, dissenting.
I respectfully dissent from the majority opinion because I do not believe the subordination agreement requires the interpretation placed on it by the majority and the doctrine of equitable subrogation is not applicable. If this case is to be reversed and remanded, I believe that the most that should be required is a vacation of the summary judgment and a remand for a determination of the allegedly ambiguous phrase.
The subordination agreement does not make any provision about the application of payments. There is no reference to any preexisting indebtedness, nor a limitation on the total indebtedness. The existing law expressed in Martuscelli v. Planters Bank & Trust Co., Ky.App., 705 S.W.2d 938 (1986) is at variance with the conclusion reached by the majority opinion. There is no clear evidence of fraud or overreaching, and there is no basis to insert into the agreement conditions which could have been stated in the original agreement.
Equitable subrogation has been limited to situations where it is necessary to avoid unjust enrichment. See United Pacific Ins. Co. v. First National Bank, Ky., 457 S.W.2d 833 (1970). Reliance on McNeely, supra, is inappropriate because there was no assignment of the first mortgage, nor any agreement by the second mortgagee to subordinate his security. It is not the function of this Court to change obligations of contract which the parties have made, nor to add a condition which was not written into the original contract. White v. Winchester Land Development Corp., Ky. App., 584 S.W.2d 56 (1979).
I believe the circuit judge and the Court of Appeals have correctly analyzed the language of the subordination agreement, and I would not disturb their decision.
