Fixed crash when the app is quitting