handle the back button to exit the application