fix a bug in finalization