Moved app exiting to a new dedicated method.