move finalize logic into its own internal method.