Refactored terminate_process! into a function.