diff --git a/src/cluster/cluster.cpp b/src/cluster/cluster.cpp
index 7193c54e3cc760a18676f7f9ff692eb9b42993fb..faabf2163db9b6902b868877742d5115144ec6d3 100644
--- a/src/cluster/cluster.cpp
+++ b/src/cluster/cluster.cpp
@@ -324,7 +324,7 @@ void cluster(const string& config_file, const string& data_file, const string& o
 		delete[] chunk_buffer;
 		MPI_Recv(&chunk_buffer_size, 1, MPI_INT, rr, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
 	      }
-	      fputc(10, output);
+	      fprintf(output, "\n");
 
 	      // now get the binary local file
 	      long buffer_size = 0;
@@ -454,7 +454,7 @@ void cluster(const string& config_file, const string& data_file, const string& o
 	  // If EOF is reached, do not send EOF character.
 	  long ptr_position = partial_output.tellg();
 	  if (ptr_position == partial_output_size) {
-	    chunk_buffer_size--;
+	    chunk_buffer[chunk_buffer_size - 1] = '\0';
 	  }
 	  // Send the size of the buffer that is being transmitted (Node-0 does not know whether it is full or not)
 	  MPI_Send(&chunk_buffer_size, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
@@ -464,8 +464,11 @@ void cluster(const string& config_file, const string& data_file, const string& o
 	long ptr_position = partial_output.tellg();
 	if (ptr_position < partial_output_size) {
 	  // Send the last partial buffer
-	  chunk_buffer_size = partial_output_size - ptr_position - 1;
+	  chunk_buffer_size = partial_output_size - ptr_position;
+	  delete[] chunk_buffer;
+	  chunk_buffer = new char[chunk_buffer_size];
 	  partial_output.read(chunk_buffer, chunk_buffer_size);
+	  chunk_buffer[chunk_buffer_size - 1] = '\0';
 	  // Send the size of the buffer that is being transmitted (Node-0 does not know whether it is full or not)
 	  MPI_Send(&chunk_buffer_size, 1, MPI_INT, 0, 1, MPI_COMM_WORLD);
 	  // Actually send the file contents to Node-0