consolidate some of the application switching code