Added finalization logic