Modify the finalize method