     noInterrupts();
     m64OpenSuccess = true;
     finished = false;
-    bufferPos = -1;
-    bufferALoaded = false;
-    bufferBLoaded = false;
+    initBuffers();
+    curFrame = 0;
+    numFrames = newNumFrames;
     interrupts();
  
     return true;
 }
 
-
 static void updateInputBuffer() {
-    if (finished || !m64OpenSuccess)
+    if (finished || !m64File.isOpen())
       return;
-  
-    long readBytes = 0;
-    if (bufferPos == -1) {
-        // Initially, both of our buffers are not in use
-        bufferPos = 0;
-        bufferAInUse = false;
-        bufferBInUse = false;
-    }
-    else {
-        // Calculate next buffer position
-        // Wrap position
-
-        // Calculate which buffer (A or B) is in use
-        if (bufferPos < INPUT_BUFFER_SIZE / 2) {
-            // Verify the buffer in use is loaded
-            if (!bufferALoaded) {
-                Serial.println(F("Error: New input was not loaded in buffer."));
-            }
-
-            // Clear old buffer when loading
-            if (!bufferAInUse) {
-                bufferBLoaded = false;
-            }
-            
-            bufferAInUse = true;
-            bufferBInUse = false;
-        } else {
-            if (!bufferBLoaded) {
-                Serial.println(F("Error: New input was not loaded in buffer."));
-            }
-
-            // Clear old buffer when loading
-            if (!bufferBInUse) {
-                bufferALoaded = false;
-            }
-            
-            bufferAInUse = false;
-            bufferBInUse = true;
-        }
-    }
-    
-    // If we have loaded all inputs, wrap up
-    if (bufferEndPos != -1) {
-        // Perform one more input then end once the last input data has been queued.
-        if (bufferOneMore && bufferPos == bufferEndPos) 
-            bufferOneMore = false;
-            
-        return;
-    }
   
     // Check for file end
     if (!m64File.available()) {
-//        screen.println(F("End of M64 loaded into buffer"));
-        
-        // Set end
-        if (!bufferAInUse) {
-            // End of buffer B marks end when
-            bufferEndPos = INPUT_BUFFER_SIZE - 1;
-        } 
-        else if (!bufferBInUse) {
-            // End of buffer A marks end
-            bufferEndPos = INPUT_BUFFER_SIZE/2 - 1;
-        } else {
-            // Da fuq? (This should never happen)
-            Serial.println(F("Unexpected ending of input file"));
-      
-            // End immediatley
-            bufferEndPos = 0;
-            finished = true;
-        }
-    
-        // Close file
         m64File.close();
         return;
     }
-  
-    // Load buffer A when its not in use
-    if (!bufferALoaded && !bufferAInUse) {
-        //Serial.println(F("Loading inputs into buffer A"));
-        // Read bytes
-        readBytes = m64File.read(inputBuffer, INPUT_BUFFER_SIZE*2);
-        if (readBytes == 0) {
-            Serial.println(F("Failed to read next inputs from file. (This is recoverable)"));
-        }
-        else {
-            bufferALoaded = true;
-            if (readBytes != INPUT_BUFFER_SIZE*2) {
-//                screen.println(F("End of M64 file found. Loading remaining bytes."));
-                bufferEndPos = readBytes / 4 - 1;
-                // Close file
-                m64File.close();
-            }
-        }
-    }
-    // Load buffer B when its not in use
-    else if (!bufferBLoaded && !bufferBInUse) {
-        //Serial.println(F("Loading inputs into buffer B"));
-        // Read bytes
-        readBytes = m64File.read(inputBuffer + (INPUT_BUFFER_SIZE / 2), INPUT_BUFFER_SIZE*2);
-        if (readBytes == 0) {
-            Serial.println(F("Failed to read next inputs from file. (This is recoverable)"));
-        }
-        else {
-            bufferBLoaded = true;
-            if (readBytes != INPUT_BUFFER_SIZE*2) {
-//                screen.println(F("End of M64 file found. Loading remaining bytes."));
-                // buffer end is offset from middle
-                bufferEndPos = INPUT_BUFFER_SIZE / 2 + readBytes / 4 - 1;
-                // Close file
-                m64File.close();
-            }
-        }
-    }
+
+    size_t availableSize;
+    size_t writePos = getNextRegion(availableSize);
+
+    // Optimized chunk reads
+    if ((availableSize < 512 && (writePos % 512) == 0) || !availableSize)
+        return;
+
+    int readBytes = m64File.read(inputBuffer + writePos, availableSize);
+    if (readBytes <= 0) {
+      lockedPrintln(F("W:Failed to read next inputs from file. (This is recoverable)"));
+      return;
+    }
+
+    noInterrupts();
+    bufferEndPos = writePos + readBytes;
+    bufferHasData = true;
+    interrupts();
 }
 
 static void startTimer()

            break;

        case -1:
            Serial.println(F("Timed out reading N64 command"));
            waitForIdle(1000);
            break;

        default:
            Serial.print(F("Unknown command: 0x"));
            Serial.println(n64_command, HEX);
            break;
    }

    *config = oldConfig;

    interrupts();

  } else if (cmd.startsWith("L:")) {
    emitList(cmd.substring(2));
  } else if (cmd.startsWith("MK:")) {
    lockedPrintln("MK:", sd.mkdir(cmd.substring(3).c_str()));
  } else if (cmd.startsWith("CR:")) {
    if (writeFile.isOpen()) {
      writeFile.close();
    }
    if (writeFile.open(&sd, cmd.substring(3).c_str(), O_WRITE | O_CREAT | O_TRUNC)) {
      lockedPrintln("CR:OK");
    } else {
      lockedPrintln("CR:NAK");
    }
  } else if (cmd.startsWith("AP:")) {
    appendData(hextobin(cmd.substring(3)));
  } else if (cmd.startsWith("IN:")) {
    size_t len = appendInputs(hextobin(cmd.substring(3)));
    lockedPrintln("IN:", len);
  } else if (cmd.startsWith("CL:")) {
    writeFile.close();
    lockedPrintln("CL:OK");
  } else if (cmd.startsWith("PM:")) {
    setPinMode(cmd.substring(3));
  } else if (cmd.startsWith("DW:")) {
    writePin(cmd.substring(3));
  } else {
    lockedPrintln("E:Unknown CMD:", cmd.c_str());
  }
}

#define MAX_CMD_LEN 4096
#define MAX_LOOP_LEN 10240

static void inputLoop()
{
  int newChar;
  int charsRead = 0;
  while ((newChar = Serial.read()) != -1 && (charsRead++ <= MAX_LOOP_LEN)) {
    if (newChar == '\n') {
      if (skippingInput)
        Serial.println("E:Skipped too-long line");
      else
        handleCommand(inputString);
      inputString = "";
      skippingInput = false;
    } else if (inputString.length() > MAX_CMD_LEN) {
      skippingInput = true;
    } else {
      inputString += (char)newChar;
