(a) After the liability ofwel the bail bondsman or surety has become fixed by forfeiture, and before payment, the bail bondsman or surety may be exonerated from the liability by the surrender of the defendant and the payment of all costs; but may be exonerated from costs also if, in the opinion ofwel the court, the bail bondsman or surety has been