tidy termination code