Add a termination function