fix terminate func