
    In re: Scott HEITKAMP and Darcy Heitkamp, doing business as Wyndmere Builders, Debtors, Kip M. KALER, as trustee for Scott Heitkamp and Darcy Heitkamp, dba Wyndmere Builders, Plaintiff-Appellee, v. COMMUNITY FIRST NATIONAL BANK, Defendant-Appellant, Tim Herbranson, doing business as Herbranson Cabinets; Strata Corporation; Northland Truss Systems, Inc.; Dennis Johnk, doing business as Dennis’ Floor Covering; ABC, Inc., doing business as ABC Seamless, Inc.; Fargo Glass & Paint Company; Lincoln State Bank of Harrison; The Park Company/Better Homes and Gardens, Defendants.
    No. 97-2355.
    United States Court of Appeals, Eighth Circuit.
    Submitted Feb. 12, 1998.
    Decided March 11, 1998.
    
      Roger J. Minch, Fargo, ND, argued, for Defendant-Appellant.
    Kip Kaler, Fargo, ND, argued, Bruce D. Johnson, on the brief, for Plaintiff-Appellee.
    Before FAGG, JOHN R. GIBSON, and MURPHY, Circuit Judges.
   FAGG, Circuit Judge.

Scott and Darcy Heitkamp build and sell homes in Wyndmere, North Dakota. In the course of their business, they borrowed money from Community First National Bank and maintained credit with several subcontractors. The bank initially loaned the Heit-kamps $50,000 to build a certain house. A mortgage secured the loan. The Heitkamps ran out of cash before completing the project and obtained another loan for $40,000 from the bank in November 1995. Rather than giving the Heitkamps the money, the bank issued cashier’s checks payable to specific subcontractors who supplied goods or services to construct the house. At the bank’s direction, the Heitkamps obtained mechanic’s lien waivers from the subcontractors in exchange for the checks. The Heitkamps also gave the bank a second mortgage on the house, but because of an oversight, the bank did not record the mortgage until March 1, 1996.

Three days later, the Heitkamps filed a Chapter 7 bankruptcy petition. The mortgaged house was sold, and the bank and several subcontractors asserted rights to the proceeds. The bankruptcy trustee brought an adversary proceeding to set aside the Heitkamps’ transfer of the second mortgage interest to the bank under 11 U.S.C. § 547(b), which permits avoidance of certain transfers of the debtor’s interest in property. The bankruptcy court set the transfer aside, rejecting the bank’s argument that the earmarking doctrine prevented avoidance of the mortgage’s transfer. The district court affirmed. The bank appeals, and we reverse.

According to the earmarking doctrine, there is no avoidable transfer of the debtor’s property interest when a new lender and a debtor agree to use loaned funds to pay a specified antecedent debt, the agreement’s terms are actually performed, and the transaction viewed as a whole -does not diminish the debtor’s estate. See McCuskey v. National Bank of Waterloo (In re Bohlen Enters., Ltd.), 859 F.2d 561, 566 (8th Cir.1988). No, avoidable transfer is made because the loaned funds never become part of the debtor’s property. See id. Instead, a new creditor merely steps into the shoes of an old creditor. See Buckley v. Jeld-Wen, Inc. (In re Interior Wood Prods. Co.), 986 F.2d 228, 231 (8th Cir.1993). Application of the earmarking doctrine is not limited, to situations in which the new creditor is secondarily liable for the earlier debt, -but extends to situations where “any third party ... pays down a debt of the debtor ... because [the] payments ... would have no effect on the estate of the debtor.” Stover v. Fulkerson (In re Bruening), 113 F.3d 838, 841 (8th Cir.1997); see Hansen v. MacDonald Meat Co. (In re Kemp Pac. Fisheries, Inc.), 16 F.3d 313, 316 n. 2 (9th Cir.1994) (per curiam) (earmarking doctrine not limited to protection of guarantors); Steinberg v. NCNB Nat’l Bank of N.C. (In re Grabill Corp.), 135 B.R. 101, 109 (Bkrtcy.N.D.Ill.1991) (same); Tolz v. Barnett Bank of S. Fla., N.A. (In re Safe-T-Brake of S. Fla., Inc.), 162 B.R. 359, 364 (Bkrtcy.S.D.Fla.1993) (“[e]aselaw has extended the earmarking doctrine beyond the guarantor scenario”). “[R]egardless of the lender’s prior relationship with the debtor, or lack thereof, replacing one creditor with another of equal priority does not diminish the estate and thus no voidable [transfer] results.” In re Safe-T-Brake, 162 B.R. at 364 (citing In re Bohlen, 859 F.2d at 565-66). Thus, the doctrine applies when a security interest is given for funds used to pay secured debts, see id.; In re Kemp, 16 F.3d at 316, but not when a security interest is given for funds used to pay an unsecured debt, see Brown v. Mt. Prospect State Bank (In re Muncrief), 900 F.2d 1220,1224 n. 4 (8th Cir.1990).

The earmarking doctrine applies in this case. The bank and the Heitkamps agreed the secured funds would be used to pay specific preexisting debts, the agreement was performed, and the transfer of the mortgage interest did not diminish the amount available for distribution to the Heitkamps’ creditors. See In re Bohlen, 859 F.2d at 566. Before the loan, the Heitkamps owed subcontractors $40,000 secured by the house for goods and services rendered. Afterwards, the Heitkamps owed the bank $40,000 secured by the house for a cash loan used to pay the subcontractors. The Heitkamps’ assets and net obligations remained the same. Essentially, the bank took over the subcontractors’ security interest in the house. See International Ventures, Inc. v. Block Props. VII (In re International Ventures, Inc.), 214 B.R. 590, 596 (Bkrtcy.E.D.Ark.1997). The subcontractors had a statutory lien against the house, see N.D. Cent.Code § 35-27-03 (1987), and could have perfected a security interest in the house even after the Heit-kamps filed for bankruptcy, see id. §§ 35-27-13, -14; 11 U.S.C. §§ 362(b)(3), 546(b)(1). The bank required the Heitkamps to obtain mechanic’s lien waivers from the subcontrae-tors, and the subcontractors specifically released their interest in the house. Because the transfer of the mortgage interest to the bank merely replaced the subcontractors’ security interest, there was no transfer of the Heitkamps’ property interest avoidable under § 547(b). In these circumstances, recognition of the bank’s security interest does not give the bank an unfair advantage over other creditors.

In sum, the trustee had the burden to prove the earmarking doctrine does not apply, see In re International Ventures, 214 B.R. at 594; In re Safe-T-Brake, 162 B.R. at 364, 365, and failed to do so. The trustee cannot avoid the. second mortgage under § 547(b) because the trustee cannot establish the mortgage was a “transfer of an interest of the debtor in property,” an element of § 547(b). See In re Interior Wood Prods., 986 F.2d at 231. We thus reverse and remand for further proceedings consistent with this opinion.  