diff --git a/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.cpp b/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.cpp
index e2c449ba0dcce59f245854c6d5333fa82b8989cc..ef5c5e1bc4e75aa2a01057b2fdd4bbae1cd1f7a0 100644
--- a/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.cpp
+++ b/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.cpp
@@ -893,18 +893,17 @@ KWXFile::KWXFile(String basename) : HDF5FileBase()
 {
     initFile(basename);
     numElectrodes=0;
-    transformVector = new int16[MAX_TRANSFORM_SIZE];
+    transformVector.malloc(MAX_TRANSFORM_SIZE);
 }
 
 KWXFile::KWXFile() : HDF5FileBase()
 {
     numElectrodes=0;
-    transformVector = new int16[MAX_TRANSFORM_SIZE];
+    transformVector.malloc(MAX_TRANSFORM_SIZE);
 }
 
 KWXFile::~KWXFile()
 {
-    delete transformVector;
 }
 
 String KWXFile::getFileName()
diff --git a/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.h b/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.h
index f98748373b7f5be85f8e8e5604c0396a72c9c41f..a9ab171d8a715abb1acf231a7d9edb09e2e14dc5 100644
--- a/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.h
+++ b/Source/Plugins/KWIKFormat/RecordEngine/HDF5FileFormat.h
@@ -205,7 +205,8 @@ private:
     OwnedArray<HDF5RecordingData> timeStamps;
     Array<int> channelArray;
     int numElectrodes;
-    int16* transformVector;
+	HeapBlock<int16> transformVector;
+    //int16* transformVector;
 
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(KWXFile);
 };
diff --git a/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.cpp b/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.cpp
index b337df0c973a89b07e4459f4343ffd0e99e1a8be..3de43b2abd9cad7b3cfcce842d5c5249f99e9ad6 100644
--- a/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.cpp
+++ b/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.cpp
@@ -22,21 +22,19 @@
  */
 
 #include "HDF5Recording.h"
-#define MAX_BUFFER_SIZE 10000
+#define MAX_BUFFER_SIZE 40960
 #define CHANNEL_TIMESTAMP_PREALLOC_SIZE 16
 #define TIMESTAMP_EACH_NSAMPLES 1024
 
-HDF5Recording::HDF5Recording() : processorIndex(-1), hasAcquired(false)
+HDF5Recording::HDF5Recording() : processorIndex(-1), hasAcquired(false), bufferSize(MAX_BUFFER_SIZE)
 {
     //timestamp = 0;
-    scaledBuffer = new float[MAX_BUFFER_SIZE];
-    intBuffer = new int16[MAX_BUFFER_SIZE];
+    scaledBuffer.malloc(MAX_BUFFER_SIZE);
+    intBuffer.malloc(MAX_BUFFER_SIZE);
 }
 
 HDF5Recording::~HDF5Recording()
-{
-    delete scaledBuffer;
-    delete intBuffer;
+{	
 }
 
 String HDF5Recording::getEngineID() const
@@ -67,6 +65,9 @@ void HDF5Recording::registerProcessor(const GenericProcessor* proc)
 
 void HDF5Recording::resetChannels()
 {
+	scaledBuffer.malloc(MAX_BUFFER_SIZE);
+	intBuffer.malloc(MAX_BUFFER_SIZE);
+	bufferSize = MAX_BUFFER_SIZE;
     processorIndex = -1;
     fileArray.clear();
 	channelsPerProcessor.clear();
@@ -173,6 +174,7 @@ void HDF5Recording::closeFiles()
     {
         if (fileArray[i]->isOpen())
         {
+			std::cout << "Closed file " << i << std::endl;
             fileArray[i]->stopRecording();
             fileArray[i]->close();
             bitVoltsArray[i]->clear();
@@ -196,11 +198,18 @@ void HDF5Recording::startChannelBlock()
 
 void HDF5Recording::writeData(int writeChannel, int realChannel, const float* buffer, int size)
 {
+	if (size > bufferSize) //Shouldn't happen, and if it happens it'll be slow, but better this than crashing. Will be reset on reset.
+	{
+		std::cerr << "Write buffer overrun, resizing to" << size << std::endl;
+		bufferSize = size;
+		scaledBuffer.malloc(size);
+		intBuffer.malloc(size);
+	}
 	double multFactor = 1 / (float(0x7fff) * getChannel(realChannel)->bitVolts);
 	int index = processorMap[getChannel(realChannel)->recordIndex];
-	FloatVectorOperations::copyWithMultiply(scaledBuffer, buffer, multFactor, size);
-	AudioDataConverters::convertFloatToInt16LE(scaledBuffer, intBuffer, size);
-	fileArray[index]->writeRowData(intBuffer, size, recordedChanToKWDChan[writeChannel]);
+	FloatVectorOperations::copyWithMultiply(scaledBuffer.getData(), buffer, multFactor, size);
+	AudioDataConverters::convertFloatToInt16LE(scaledBuffer.getData(), intBuffer.getData(), size);
+	fileArray[index]->writeRowData(intBuffer.getData(), size, recordedChanToKWDChan[writeChannel]);
 
 	int sampleOffset = channelLeftOverSamples[writeChannel];
 	int blockStart = sampleOffset;
diff --git a/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.h b/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.h
index cc0ac27b954afd80499fe7addf72c54e8bc30dbc..7364746c35b1fc26d2b3a4256a47342f6684716f 100644
--- a/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.h
+++ b/Source/Plugins/KWIKFormat/RecordEngine/HDF5Recording.h
@@ -62,8 +62,11 @@ private:
     OwnedArray<HDF5RecordingInfo> infoArray;
     ScopedPointer<KWEFile> eventFile;
     ScopedPointer<KWXFile> spikesFile;
-    float* scaledBuffer;
-    int16* intBuffer;
+	HeapBlock<float> scaledBuffer;
+	HeapBlock<int16> intBuffer;
+	int bufferSize;
+    //float* scaledBuffer;
+    //int16* intBuffer;
 
     bool hasAcquired;
 
diff --git a/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp b/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp
index c76639c604bbef6ed500441c7523e326fa6d4549..b73e8a06773f6314ae4d4b55be6053cf6328d3f1 100644
--- a/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp
+++ b/Source/Processors/DataThreads/RhythmNode/RHD2000Thread.cpp
@@ -44,8 +44,8 @@
 #define REGISTER_59_MISO_B  58
 #define RHD2132_16CH_OFFSET 8
 
-//#define DEBUG_EMULATE_HEADSTAGES 8
-//#define DEBUG_EMULATE_64CH
+#define DEBUG_EMULATE_HEADSTAGES 8
+#define DEBUG_EMULATE_64CH
 
 #define INIT_STEP ( evalBoard->isUSB3() ? 256 : 60)
 
@@ -188,10 +188,10 @@ RHD2000Thread::~RHD2000Thread()
 
     //deleteAndZero(dataBlock);
 
-    delete dacStream;
-    delete dacChannels;
-    delete dacThresholds;
-    delete dacChannelsToUpdate;
+    delete[] dacStream;
+    delete[] dacChannels;
+    delete[] dacThresholds;
+    delete[] dacChannelsToUpdate;
 
 }
 
diff --git a/Source/Processors/GenericProcessor/GenericProcessor.cpp b/Source/Processors/GenericProcessor/GenericProcessor.cpp
index ffc990e41ca02b85cdca1eb19bb4686462a081d4..90e34c315a92fd011c1438e10c24f9af7f6c2d57 100755
--- a/Source/Processors/GenericProcessor/GenericProcessor.cpp
+++ b/Source/Processors/GenericProcessor/GenericProcessor.cpp
@@ -632,7 +632,7 @@ void GenericProcessor::setTimestamp(MidiBuffer& events, int64 timestamp)
                  0,
                  0,
                  0,
-                 data.length() + 1, //It doesn't hurt to send the end-string null and can help avoid issues
+                 data.sizeInBytes(), //It doesn't hurt to send the end-string null and can help avoid issues
                  (uint8*)data.getAddress(),
                  true);
 
diff --git a/Source/Processors/MessageCenter/MessageCenter.cpp b/Source/Processors/MessageCenter/MessageCenter.cpp
index 2f4540c727532884edccfb507e72ffcf6dafa401..ba17df9bb0fbf39d45a264c72de166666146715f 100644
--- a/Source/Processors/MessageCenter/MessageCenter.cpp
+++ b/Source/Processors/MessageCenter/MessageCenter.cpp
@@ -134,7 +134,7 @@ void MessageCenter::process(AudioSampleBuffer& buffer, MidiBuffer& eventBuffer)
                  0,
                  0,
                  0,
-                 data.length() + 1, //It doesn't hurt to send the end-string null and can help avoid issues
+                 data.sizeInBytes(), //It doesn't hurt to send the end-string null and can help avoid issues
                  (uint8*)data.getAddress());
 
         needsToSendTimestampMessage = false;
@@ -153,7 +153,7 @@ void MessageCenter::process(AudioSampleBuffer& buffer, MidiBuffer& eventBuffer)
                  0,
                  0,
                  0,
-                 data.length()+1, //It doesn't hurt to send the end-string null and can help avoid issues
+                 data.sizeInBytes(), //It doesn't hurt to send the end-string null and can help avoid issues
                  (uint8*) data.getAddress());
 
         newEventAvailable = false;
diff --git a/Source/Processors/RecordNode/RecordNode.cpp b/Source/Processors/RecordNode/RecordNode.cpp
index b41604eab08cfdc03cf1ab72789d4190ae33547d..8e56c9b824518c2a35f383b2fc5a964b78ce5e95 100755
--- a/Source/Processors/RecordNode/RecordNode.cpp
+++ b/Source/Processors/RecordNode/RecordNode.cpp
@@ -334,7 +334,7 @@ void RecordNode::setParameter(int parameterIndex, float newValue)
     {
 
 
-        // std::cout << "STOP RECORDING." << std::endl;
+        std::cout << "STOP RECORDING." << std::endl;
 
         if (isRecording)
         {
@@ -345,7 +345,7 @@ void RecordNode::setParameter(int parameterIndex, float newValue)
 			m_recordThread->waitForThreadToExit(2000);
 			while (m_recordThread->isThreadRunning())
 			{
-				
+				std::cerr << "RecordEngine timeout" << std::endl;
 				if (AlertWindow::showOkCancelBox(AlertWindow::WarningIcon, "Record Thread timeout",
 					"The recording thread is taking too long to close.\nThis could mean there is still data waiting to be written in the buffer, but it normally "
 					"shouldn't take this long.\nYou can either wait a bit more or forcefully close the thread. Note that data might be lost or corrupted"
diff --git a/Source/Processors/RecordNode/RecordThread.cpp b/Source/Processors/RecordNode/RecordThread.cpp
index 431c924c1f3fb536b94dd77e74eeba708ad84467..b49d862220853c38d81d3623dd578a9ac464c949 100644
--- a/Source/Processors/RecordNode/RecordThread.cpp
+++ b/Source/Processors/RecordNode/RecordThread.cpp
@@ -96,11 +96,13 @@ void RecordThread::run()
 	{
 		writeData(dataBuffer, BLOCK_MAX_WRITE_SAMPLES, BLOCK_MAX_WRITE_EVENTS, BLOCK_MAX_WRITE_SPIKES);
 	}
+	std::cout << "Exiting record thread" << std::endl;
 	//4-Before closing the thread, try to write the remaining samples
 	if (!closeEarly)
 	{
 		writeData(dataBuffer, -1, -1, -1);
 
+		std::cout << "Closing files" << std::endl;
 		//5-Close files
 		EVERY_ENGINE->closeFiles();
 	}