Adjustments to fix the app crashing on quit.