Restructured for automatic app switching.