Fixing a bug related to when the app should close so the user can resume working