The proceeds of the sale of encumbered property shall be distributed by the judgment of the court as follows:

(1) To pay the property’s just proportion of the general costs of the suit.

(2) To pay the costs of the reference.

(3) To satisfy the several liens in their order of priority, by payment of the sums due and to become due, according to the judgment.

(4) The residue among the owners of the property sold, according to their respective shares. [Amended by 2003 c.576 § 366]