Section 81. The defendant may surrender himself at any time before a default, in the same manner as sureties in criminal cases may surrender their principal, and the court shall thereupon order the bank books to be reassigned and the money or bonds so deposited to be returned to the person in whose name the deposit is made or to his order. At any time after default, on the surrender or recaption of the defendant, the court may order the whole or any part of the money so deposited or of the bonds, or of the amount of the net proceeds of the sale of said bonds, or the bank books, or the whole or any part of the amount collected from the depository thereunder, to be returned to the person in whose name the deposit is made or to his order. If the amount realized by sale or collection pursuant to the preceding section exceeds the amount of the recognizance, the court shall, on an application made at any time, order such excess to be returned to the party found by the court to be entitled thereto. The foregoing provisions shall apply to cases in which forfeiture has been ordered.