Fixed a bug with app switching

And minor control flow change (that needs testing on a 5S).