The trustee or mortgagee shall apply the proceeds of the sale as follows:
(1) To the expenses of the sale, including compensation of the trustee or mortgagee and a reasonable fee by the attorney;
(2) To the indebtedness owed;
(3) To all persons having recorded liens subsequent to the interest of the trustee or mortgagee as their interests may appear in the order of the priority; and
(4) The surplus, if any, to the grantor of the trust deed or to the successor in interest of the grantor entitled to the surplus.