(a) Any mortgage or other instrument given for the purpose of creating a lien on real property, when so expressed therein or when so expressed in a separate instrument or other agreement specifically referred to therein and incorporated by reference (which instrument or other agreement need not be recorded), may secure not only existing indebtedness, but also future advances, whether such advances are obligatory or to be made at the option of the lender, or otherwise, and whether made before or after default or maturity or other similar events, to the same extent as if such future advances were made on the date of the execution of such mortgage or other such instrument, although there may be no advance made at the time of the execution of such mortgage or other instrument and although there may be no indebtedness outstanding at the time any advance is made. Such lien, as to third persons with or without actual knowledge thereof, shall be valid as to all such indebtedness and future advances from the time the mortgage or other such instrument is recorded or filed in the proper office as provided by law. The total amount of the indebtedness having the priority established by such lien may decrease or increase from time to time, but the total unpaid principal balance at any 1 time shall not exceed the maximum principal amount of the obligation which must be specified in such mortgage or other such recorded instrument. Any mortgage or other instrument to which this subsection applies, and all such existing indebtedness, future advances and interest thereon, shall have preference to and priority over any lien, other than those liens the priority of which is governed by § 2901 of this title, which is subsequent in time to the time such mortgage or other such instrument is recorded or filed in the proper office as provided by law.
(b) In addition to the stated indebtedness, a mortgage or other instrument given for the purpose of creating a lien on real property may secure disbursements and other advances thereunder for the payment of taxes, assessments, maintenance charges, insurance premiums or costs relating to the property encumbered by such mortgage or other instrument, for the discharge of liens having priority over the lien of such mortgage or other instrument, for the curing of waste of the property that is the subject of the lien, for the indemnification obligations regarding environmental liabilities of the property that is the subject of the lien, and for the payment of service charges and expenses incurred by reason of default, and including late charges, attorneys' fees and court costs, if such mortgage or other such instrument states that it shall secure any such advances and disbursements, together with all interest thereon. Any mortgage or other instrument to which this subsection applies, and all such stated indebtedness, disbursements and other advances expressed therein and interest thereon, shall have preference to and priority over any lien, other than those liens the priority of which is governed by § 2901 of this title, which is subsequent in time to the time such mortgage or other such instrument is recorded or filed in the proper office as provided by law.