diff --git a/mergecounts.wdl b/mergecounts.wdl
index 8aa2a92e934ab26572148e771ac546b4bf78dd5f..75d51237554ef1977db31dd8b2a3456ae5e66fca 100644
--- a/mergecounts.wdl
+++ b/mergecounts.wdl
@@ -12,7 +12,7 @@ task MergeCounts {
         set -e -o pipefail
         mkdir -p ${sub(outputFile, basename(outputFile) + "$", "")}
         ${preCommand}
-        R --no-save --slave <<CODE > ${outputFile}
+        R --no-save --slave <<CODE
             library(dplyr)
             library(reshape2)
 
@@ -23,7 +23,7 @@ task MergeCounts {
             header <- ${true="TRUE" false="FALSE" inputHasHeader}
 
             d <- do.call(rbind, lapply(listOfFiles, function(file){
-                d <- read.table(file, header=header, comment.char="#")
+                d <- read.table(file, sep="\t", header=header, comment.char="#")
 
                 splitPath <- strsplit(file, "/")[[1]]
                 colnames(d)[valueI] <- sub("\\\.[^\\\.]*$", "",
@@ -34,7 +34,7 @@ task MergeCounts {
             }))
 
             d <- d %>% dcast(feature ~ sample, value.var="count")
-            write.table(d, sep="\t", quote=FALSE, row.names=FALSE)
+            write.table(d, file="${outputFile}", sep="\t", quote=FALSE, row.names=FALSE)
         CODE
     >>>