remove monkey patch of finalize; use state machine