(b)the assets of the firm, including any sums contributed by the partners to make up deficiencies of capital, shall be applied in the following manner and order:—(i)in paying the debts of the firm to third parties;(ii)in paying to each partner rateably what is due to him from the firm for advances as distinguished from capital;(iii)in paying to each partner rateably what is due to him on account of capital; and(iv)the residue, if any, shall be divided among the partners in the proportions in which they were entitled to share profits.