added recursive function to do terminal switching