Terminate the application gracefully.