exposed terminate function