diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc
index 2494d5b..6d4d797 100644
--- a/src/QGCApplication.cc
+++ b/src/QGCApplication.cc
@@ -335,6 +335,7 @@ void QGCApplication::_shutdown(void)
 QGCApplication::~QGCApplication()
 {
     // Place shutdown code in _shutdown
+    _app = NULL;
 }
 
 void QGCApplication::_initCommon(void)
diff --git a/src/QmlControls/AppMessages.cc b/src/QmlControls/AppMessages.cc
index dc9db5f..fab8b7b 100644
--- a/src/QmlControls/AppMessages.cc
+++ b/src/QmlControls/AppMessages.cc
@@ -92,7 +92,8 @@ void AppLogModel::threadsafeLog(const QString message)
     insertRows(line, 1);
     setData(index(line), message, Qt::DisplayRole);
 
-    if (_logFile.fileName().isEmpty() && qgcApp()->logOutput()) {
+    if (qgcApp() && qgcApp()->logOutput() && _logFile.fileName().isEmpty()) {
+        qDebug() << _logFile.fileName().isEmpty() << qgcApp()->logOutput();
         QGCToolbox* toolbox = qgcApp()->toolbox();
         // Be careful of toolbox not being open yet
         if (toolbox) {
@@ -110,5 +111,6 @@ void AppLogModel::threadsafeLog(const QString message)
     if (_logFile.isOpen()) {
         QTextStream out(&_logFile);
         out << message << "\n";
+        _logFile.flush();
     }
 }
diff --git a/src/Terrain/TerrainQuery.cc b/src/Terrain/TerrainQuery.cc
index ed7ebb4..b1d7030 100644
--- a/src/Terrain/TerrainQuery.cc
+++ b/src/Terrain/TerrainQuery.cc
@@ -595,6 +595,7 @@ void TerrainAtCoordinateBatchManager::_coordinateHeights(bool success, QList<dou
     int currentIndex = 0;
     foreach (const SentRequestInfo_t& sentRequestInfo, _sentRequests) {
         if (!sentRequestInfo.queryObjectDestroyed) {
+            qCDebug(TerrainQueryLog) << "TerrainAtCoordinateBatchManager::_coordinateHeights returned TerrainCoordinateQuery:count" <<  sentRequestInfo.terrainAtCoordinateQuery << sentRequestInfo.cCoord;
             disconnect(sentRequestInfo.terrainAtCoordinateQuery, &TerrainAtCoordinateQuery::destroyed, this, &TerrainAtCoordinateBatchManager::_queryObjectDestroyed);
             QList<double> requestAltitudes = heights.mid(currentIndex, sentRequestInfo.cCoord);
             sentRequestInfo.terrainAtCoordinateQuery->_signalTerrainData(true, requestAltitudes);