Refactor and add a terminate mojo