Clean up terminal exit, write out to output