Section 6. That where the amount, or any part thereof of any judgment, recovered in pursuance of this act, shall be collected by execution or otherwise, the same shall be taken in open court, by the sheriff or other officer having received the same; and it shall be the duty of the judges of the said court, being notified of the payment of money as aforesaid, to order and decree a distribution of the same, in the following order, to wit: First--That so much thereof as shall be necessary, shall be applied to pay the costs on such prosecution, and on the proceedings before the magistrate who shall have taken such recognizance, together with such reasonable compensation as the court shall adjudge to the officers employed to arrest the person or persons, on whose default the said recognizance was forfeited, as well as to those employed in the conduct and collection of such judgment: Second--That so much of the residue thereof, as will satisfy the amount of damage sustained by any person, by reason of the commission of such crime or misdemeanor, with interest thereon, to be counted from the date of the commission of such crime or misdemeanor, shall be applied thereto: Third--And that the residue of any moneys collected as aforesaid, be paid said county, or into the treasury of the commonwealth, as the case may be: Provided, That it shall be in the power of the court, in all cases where the forfeiture is stricken off, before any money is paid into court as aforesaid, to order the county, or the defendant, to pay the costs and expenses hereinbefore provided for, as the case may require.