Small refactor to allow improved termination function