(a) Upon the confirmation of such sale, the proceeds arising therefrom shall be delivered by the sheriff to the clerk of said court to be applied by him as follows:
(i) To the payment of all costs of such action and sale, including an attorney fee to the lienholder's attorney to be allowed by the court;
(ii) To the payment of all sums due the lienholder, including the value of all improvements placed on said land by said lienholder and those under whom he holds;
(iii) The balance, if any, to be paid to the prior owners of said land and those having an interest therein, as their interests may appear.