Fixed a bug in the finalize operation.