Fix a few crashing bugs on app resume