diff --git a/star.wdl b/star.wdl
index 9e01477a01741bd7f0e426582c416b5b833903f6..d7d3b7b595953704ab0de936b82e1ba7405fe279 100644
--- a/star.wdl
+++ b/star.wdl
@@ -18,6 +18,9 @@ task Star {
     #TODO needs to be extended for all possible output extensions
     Map[String, String] samOutputNames = {"BAM SortedByCoordinate": "sortedByCoord.out.bam"}
 
+    # converts String? to String for use as key (for the Map above) in output
+    String key = select_first([outSAMtype, "BAM SortedByCoordinate"])
+
     command {
         set -e -o pipefail
         mkdir -p ${sub(outFileNamePrefix, basename(outFileNamePrefix) + "$", "")}
@@ -35,7 +38,7 @@ task Star {
     }
 
     output {
-        File bamFile = outFileNamePrefix + "Aligned." +  samOutputNames["${outSAMtype}"]
+        File bamFile = outFileNamePrefix + "Aligned." +  samOutputNames[key]
     }
 
     runtime {