The money arising from the sale of mortgaged property sold under the regulations prescribed in this part shall be paid to the person foreclosing the mortgage unless claimed by some other lien which by law has priority of payment over the mortgage; and, when there is any surplus after paying off the mortgage and other liens, the surplus shall be paid to the mortgagor or his agent.