Fix a bug in finalize.