diff --git a/Source/Plugins/BinaryWriter/BinaryRecording.cpp b/Source/Plugins/BinaryWriter/BinaryRecording.cpp
index 986e90e72f9e5a4c145bc1efe1cf42f2b7ba4a69..9542f84937c0176e1d19b3e099fdfa19f8cb0c6d 100644
--- a/Source/Plugins/BinaryWriter/BinaryRecording.cpp
+++ b/Source/Plugins/BinaryWriter/BinaryRecording.cpp
@@ -49,13 +49,52 @@ void BinaryRecording::openFiles(File rootFolder, int experimentNumber, int recor
 	//Open channel files
 	int nProcessors = getNumRecordedProcessors();
 
-	for (int i = 0; i < nProcessors; i++)
+	m_channelIndexes.insertMultiple(0, 0, getNumRecordedChannels());
+	m_fileIndexes.insertMultiple(0, 0, getNumRecordedChannels());
+
+	int lastId = 0;
+	for (int proc = 0; proc < nProcessors; proc++)
 	{
-		const RecordProcessorInfo& pInfo = getProcessorInfo(i);
-		File datFile(basepath + "_" + String(pInfo.processorId) + "_" + String(recordingNumber) + ".dat");
-		ScopedPointer<SequentialBlockFile> bFile = new SequentialBlockFile(pInfo.recordedChannels.size(), samplesPerBlock);
-		if (bFile->openFile(datFile))
-			m_DataFiles.add(bFile.release());
+		const RecordProcessorInfo& pInfo = getProcessorInfo(proc);
+		int recChans = pInfo.recordedChannels.size();
+
+		for (int chan = 0; chan < recChans; chan++)
+		{
+			int recordedChan = pInfo.recordedChannels[chan];
+			int realChan = getRealChannel(recordedChan);
+			const DataChannel* channelInfo = getDataChannel(realChan);
+			int sourceId = channelInfo->getSourceNodeID();
+			int sourceSubIdx = channelInfo->getSubProcessorIdx();
+			int nInfoArrays = m_dataChannels.size();
+			bool found = false;
+			for (int i = lastId; i < nInfoArrays; i++)
+			{
+				if (sourceId == m_dataChannels.getReference(i)[0]->getSourceNodeID() && sourceSubIdx == m_dataChannels.getReference(i)[0]->getSubProcessorIdx())
+				{
+					m_channelIndexes.set(recordedChan, m_dataChannels.getReference(i).size());
+					m_fileIndexes.set(recordedChan, i);
+					m_dataChannels.getReference(i).add(getDataChannel(realChan));
+					found = true;
+					break;
+				}
+			}
+			if (!found)
+			{
+				File datFile(basepath + "_" + String(pInfo.processorId) + "_" + String(sourceId) + "." + String(sourceSubIdx) + "_" + String(recordingNumber) + ".dat");
+				ScopedPointer<SequentialBlockFile> bFile = new SequentialBlockFile(pInfo.recordedChannels.size(), samplesPerBlock);
+				if (bFile->openFile(datFile))
+					m_DataFiles.add(bFile.release());
+				else
+					m_DataFiles.add(nullptr);
+
+				ContinuousGroup newGroup;
+				newGroup.add(getDataChannel(realChan));
+				m_dataChannels.add(newGroup);
+				m_fileIndexes.set(recordedChan, nInfoArrays);
+				m_channelIndexes.set(recordedChan, 0);
+				
+			}
+		}
 	}
 	int nChans = getNumRecordedChannels();
 	//Origin Timestamp
@@ -130,7 +169,7 @@ void BinaryRecording::writeData(int writeChannel, int realChannel, const float*
 	FloatVectorOperations::copyWithMultiply(m_scaledBuffer.getData(), buffer, multFactor, size);
 	AudioDataConverters::convertFloatToInt16LE(m_scaledBuffer.getData(), m_intBuffer.getData(), size);
 
-	m_DataFiles[getProcessorFromChannel(writeChannel)]->writeChannel(getTimestamp(writeChannel)-m_startTS[writeChannel],getChannelNumInProc(writeChannel),m_intBuffer.getData(),size);
+	m_DataFiles[m_fileIndexes[writeChannel]]->writeChannel(getTimestamp(writeChannel)-m_startTS[writeChannel],m_channelIndexes[writeChannel],m_intBuffer.getData(),size);
 }
 
 //Code below is copied from OriginalRecording, so it's not as clean as newer one
diff --git a/Source/Plugins/BinaryWriter/BinaryRecording.h b/Source/Plugins/BinaryWriter/BinaryRecording.h
index a92f2acd429f274a370618dacce59d75dfe73697..d710dd4dfa9bd8334c2a2e89b3d709694df93a66 100644
--- a/Source/Plugins/BinaryWriter/BinaryRecording.h
+++ b/Source/Plugins/BinaryWriter/BinaryRecording.h
@@ -56,7 +56,7 @@ namespace BinaryRecordingEngine
 		static RecordEngineManager* getEngineManager();
 
 	private:
-
+		typedef Array<const DataChannel*> ContinuousGroup;
 		void openSpikeFile(String basepath, int spikeIndex, int recordingNumber);
 		String generateSpikeHeader(const SpikeChannel* elec);
 		String generateEventHeader();
@@ -71,6 +71,9 @@ namespace BinaryRecordingEngine
 		int m_bufferSize;
 
 		OwnedArray<SequentialBlockFile>  m_DataFiles;
+		Array<unsigned int> m_channelIndexes;
+		Array<unsigned int> m_fileIndexes;
+		Array<ContinuousGroup> m_dataChannels;
 
 		FILE* eventFile;
 		FILE* messageFile;
diff --git a/Source/Plugins/NWBFormat/NWBRecording.cpp b/Source/Plugins/NWBFormat/NWBRecording.cpp
index 59473f86a5feb658261a9fe24bba5b553c3d5b24..081a4ff9b487fff244ebcaed34403e83a86dfc4d 100644
--- a/Source/Plugins/NWBFormat/NWBRecording.cpp
+++ b/Source/Plugins/NWBFormat/NWBRecording.cpp
@@ -59,7 +59,7 @@
 	 int lastId = 0;
 	 for (int proc = 0; proc < recProcs; proc++)
 	 {
-		 const RecordProcessorInfo procInfo = getProcessorInfo(proc);
+		 const RecordProcessorInfo& procInfo = getProcessorInfo(proc);
 		 int recChans = procInfo.recordedChannels.size();
 		 for (int chan = 0; chan < recChans; chan++)
 		 {