Ensure proper application shutdown