Also do the cleanup when the terminal is closed