     }
     else if ( request->hasArg( "diskspace" ) )
     {
-      if (  xSemaphoreTake( x_SPI_Mutex, SPI_MutexMaxWaitTime  ) )
-      {
-        if ( sdcardPresent )
+      if ( !xSemaphoreTake( x_SPI_Mutex, SPI_MutexMaxWaitTime  ) )
+      {
+        return request->send( 501, textPlainHeader, "SPI bus not available" );
+      }
+      if ( sdcardPresent )
+      {
+        snprintf( content, sizeof( content ), "%llu" , SD.totalBytes() - SD.usedBytes() );
+      }
+      xSemaphoreGive( x_SPI_Mutex );
+    }
+    else if ( request->hasArg( "files" ) )
+    {
+      if ( !xSemaphoreTake( x_SPI_Mutex, SPI_MutexMaxWaitTime ) )
+      {
+        return request->send( 501, textPlainHeader, "SPI bus not available" );
+      }
+      File root = SD.open( "/" );
+      if ( !root )
+      {
+        xSemaphoreGive( x_SPI_Mutex );
+        return request->send( 501, textPlainHeader, "No sd card present." );
+      }
+      if ( !root.isDirectory() )
+      {
+        xSemaphoreGive( x_SPI_Mutex );
+        return request->send( 400, textPlainHeader, "Not a directory");
+      }
+      File file = root.openNextFile();
+      uint8_t charCount = 0;
+      while ( file )
+      {
+        if ( !file.isDirectory() )
         {
-          snprintf( content, sizeof( content ), "%llu" , SD.totalBytes() - SD.usedBytes() );
-          xSemaphoreGive( x_SPI_Mutex );
+          size_t fileSize = file.size();
+          charCount += snprintf( content + charCount, sizeof( content ) - charCount, "%s,%s\n", file.name(), humanReadableSize( fileSize ).c_str() );
         }
-      }
-      else
-      {
-        return request->send( 501, textPlainHeader, "SPI bus not available" );
-      }
-    }
-    else if ( request->hasArg( "files" ) )
-    {
-      if (  xSemaphoreTake( x_SPI_Mutex, SPI_MutexMaxWaitTime ) )
-      {
-        File root = SD.open( "/" );
-        if ( !root )
-        {
-          xSemaphoreGive( x_SPI_Mutex );
-          return request->send( 501, textPlainHeader, "No sd card present." );
-        }
-        if ( !root.isDirectory() )
-        {
-          xSemaphoreGive( x_SPI_Mutex );
-          return request->send( 400, textPlainHeader, "Not a directory");
-        }
-
-        File file = root.openNextFile();
-        uint8_t charCount = 0;
-        while ( file )
-        {
-          if ( !file.isDirectory() )
-          {
-            size_t fileSize = file.size();
-            charCount += snprintf( content + charCount, sizeof( content ) - charCount, "%s,%s\n", file.name(), humanReadableSize( fileSize ).c_str() );
-          }
-          file = root.openNextFile();
-        }
-        xSemaphoreGive( x_SPI_Mutex );
-      }
-      else
-      {
-        return request->send( 501, textPlainHeader, "SPI bus not available" );
-      }
+        file = root.openNextFile();
+      }
+      xSemaphoreGive( x_SPI_Mutex );
     }
     else if ( request->hasArg( "hostname" ) )
     {

      tft.fillScreen( ILI9341_BLACK );
      saveStringNVS( "tftorientation", ( tftOrientation == TFT_ORIENTATION_NORMAL ) ? "normal" : "upsidedown" );
      snprintf( content, sizeof( content ), "%s", ( tftOrientation == TFT_ORIENTATION_NORMAL ) ? "normal" : "upsidedown" );
    }




  server.on( "/api/deletefile", HTTP_POST, []( AsyncWebServerRequest * request)
  {
    if ( !xSemaphoreTake( x_SPI_Mutex, SPI_MutexMaxWaitTime ) )
    {
      return request->send( 501, textPlainHeader, "SPI Bus not available" );
    }

    if ( !request->authenticate( www_username, www_password ) )
    {
      return request->requestAuthentication();
