Money realized from a foreclosure sale shall be made available for obligation and expenditure—
first to cover the costs of foreclosure provided for in section 3711 of this title;
then to pay valid tax liens or assessments prior to the mortgage;
then to service charges and advancements for taxes, assessments, and property insurance premiums;
Any surplus after payment of the foregoing shall be paid to holders of liens recorded after the mortgage and then to the appropriate mortgagor. If the person to whom such surplus is to be paid cannot be located, or if the surplus available is insufficient to pay all claimants and the claimants cannot agree on the allocation of the surplus, or if any person claiming an interest in the mortgage proceeds does not agree that some or all of the sale proceeds should be paid to a claimant as provided in this section, that part of the sale proceeds in question may be deposited by the foreclosure commissioner with an appropriate official or court authorized under law to receive disputed funds in such circumstances. If such a procedure for the deposit of disputed funds is not available, and the foreclosure commissioner files a bill of interpleader or is sued as a stakeholder to determine entitlement to such funds, the foreclosure commissioner’s necessary costs in taking or defending such action shall be deductible from the disputed funds.