Rework of finalization using garbage collection

Closes #1