diff --git a/src/nextflow b/src/nextflow
index 4a4f0cfd01661a8db2b8683ce8c25452576d3957..224341c9849e6dd31040a3904945cfb65a780d40 100755
--- a/src/nextflow
+++ b/src/nextflow
@@ -16,7 +16,7 @@
 #  limitations under the License.
 
 [[ "$NXF_DEBUG" == 'x' ]] && set -x
-NXF_VER=${NXF_VER:-'21.04.3'}
+NXF_VER=${NXF_VER:-'21.10.6'}
 NXF_ORG=${NXF_ORG:-'nextflow-io'}
 NXF_HOME=${NXF_HOME:-$HOME/.nextflow}
 NXF_PROT=${NXF_PROT:-'https'}
@@ -24,6 +24,7 @@ NXF_BASE=${NXF_BASE:-$NXF_PROT://www.nextflow.io/releases}
 NXF_TEMP=${NXF_TEMP:-$TMPDIR}
 NXF_DIST=${NXF_DIST:-$NXF_HOME/framework}
 NXF_CLI="$0 $@"
+NXF_CLI_OPTS=${NXF_CLI_OPTS:-}
 
 export NXF_CLI
 export NXF_ORG
@@ -98,10 +99,10 @@ function resolve_link() {
       realpath "$1"
     elif command -v readlink &>/dev/null; then
       local target="$1"
-      cd $(dirname $target); target=$(basename $target)
+      cd "$(dirname "$target")"; target="$(basename "$target")"
       while [ -L "$target" ]; do
         target="$(readlink "$target")"
-        cd $(dirname $target); target=$(basename $target)
+        cd "$(dirname "$target")"; target="$(basename "$target")"
       done
       echo "$(cd "$(dirname "$target")"; pwd -P)/$target"
     else
@@ -196,6 +197,10 @@ dockerize=''
 declare -a jvmopts=()
 declare -a args=("$@")
 declare -a commands=(clone config drop help history info ls pull run view node console kuberun)
+# $NXF_CLI_OPTS allow to pass arbitrary cli opts via the environment
+# note: do not wrap with quotes because the variable can be used to specify more than on option separate by blanks
+[ "$NXF_CLI_OPTS" ] && args+=($NXF_CLI_OPTS)
+
 cmd=''
 while [[ $# != 0 ]]; do
     case $1 in
@@ -333,8 +338,8 @@ else
     version_check="^(1.7|1.8)"
     version_message="Java 7 or 8"
   else
-    version_check="^(1.8|9|10|11|12|13|14|15)"
-    version_message="Java 8 or later"
+    version_check="^(1.8|9|10|11|12|13|14|15|16|17)"
+    version_message="Java 8 or later (up to 17)"
   fi
   if [[ ! $JAVA_VER =~ $version_check ]]; then
       echo_red "ERROR: Cannot find Java or it's a wrong version -- please make sure that $version_message is installed"
@@ -345,8 +350,8 @@ else
       fi
       exit 1
   fi
-  if [[ ! $JAVA_VER =~ ^(1.8|9|10|11|12|13|14|15) ]]; then
-      echo_yellow "NOTE: Nextflow is not tested with Java $JAVA_VER -- It's recommended the use of version 8 up to 15\n"
+  if [[ ! $JAVA_VER =~ ^(1.8|9|10|11|12|13|14|15|16|17) ]]; then
+      echo_yellow "NOTE: Nextflow is not tested with Java $JAVA_VER -- It's recommended the use of version 8 up to 17\n"
   elif [[ ! $JAVA_VER =~ ^(1.8|9|10|11) && $NXF_MODE == ignite ]]; then
       echo_yellow "WARN: Apache Ignite executor is not tested with Java $JAVA_VER -- It's recommended the use of version 8 up to 11\n"
   fi
@@ -373,7 +378,7 @@ fi
 [[ "$JAVA_HOME" ]] && JAVA_OPTS+=(-Dcapsule.java.home="$JAVA_HOME")
 [[ "$CAPSULE_LOG" ]] && JAVA_OPTS+=(-Dcapsule.log=$CAPSULE_LOG)
 [[ "$CAPSULE_RESET" ]] && JAVA_OPTS+=(-Dcapsule.reset=true)
-[[ "$cmd" != "run" && "$cmd" != "node" ]] && JAVA_OPTS+=(-XX:+TieredCompilation -XX:TieredStopAtLevel=1)
+[[ "$cmd" != "run" && "$cmd" != "node" ]] && JAVA_OPTS+=(-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dcom.sun.security.enableAIAcaIssuers=true)
 [[ "$NXF_OPTS" ]] && JAVA_OPTS+=($NXF_OPTS)
 [[ "$NXF_CLASSPATH" ]] && export NXF_CLASSPATH
 [[ "$NXF_GRAB" ]] && export NXF_GRAB
@@ -422,18 +427,21 @@ else
   LAUNCH_FILE="${NXF_LAUNCHER}/classpath-$(env_md5)"
 fi
 if [ -s "$LAUNCH_FILE" ] && [ "$LAUNCH_FILE" -nt "$NXF_BIN" ]; then
-    launcher=($(cat "$LAUNCH_FILE"))
+    declare -a launcher="($(cat "$LAUNCH_FILE"))"
 else
     # otherwise run the capsule and get the result classpath in the 'launcher' and save it to a file
     cli=($("$JAVA_CMD" "${JAVA_OPTS[@]}" -jar "$NXF_BIN"))
     [[ $? -ne 0 ]] && echo_red 'Unable to initialize nextflow environment' && exit 1
 
-    if [[ "$JAVA_VER" =~ ^(9|10|11|12|13|14|15) ]]; then
+    if [[ "$JAVA_VER" =~ ^(9|10|11|12|13|14|15|16|17) ]]; then
       launcher=("${cli[@]:0:1}")
       launcher+=(--add-opens=java.base/java.lang=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/java.io=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/java.nio=ALL-UNNAMED)
+      launcher+=(--add-opens=java.base/java.net=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/java.util=ALL-UNNAMED)
+      launcher+=(--add-opens=java.base/java.util.concurrent.locks=ALL-UNNAMED)
+      launcher+=(--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/java.nio.file.spi=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/sun.nio.ch=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/sun.nio.fs=ALL-UNNAMED)
@@ -442,7 +450,6 @@ else
       launcher+=(--add-opens=java.base/sun.net.www.protocol.ftp=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/sun.net.www.protocol.file=ALL-UNNAMED)
       launcher+=(--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED)
-      launcher+=(--illegal-access=deny)
       launcher+=("${cli[@]:1}")
     else
       launcher=("${cli[@]}")
diff --git a/src/nf_modules/bedtools/main.nf b/src/nf_modules/bedtools/main.nf
index f84c516ab4b869cea93dd77b7d1642a82732238c..30120ecdd4711d27f52ac0711d56a4c2a24a5e16 100644
--- a/src/nf_modules/bedtools/main.nf
+++ b/src/nf_modules/bedtools/main.nf
@@ -215,6 +215,8 @@ process nearestExon_To_Peak {
   
   script:
 """
-bedtools closest -d -a ${bed} -b ${exons} > ${bed_id}_nearestExon.bed
+bedtools closest -a ${exons} -b ${bed} -D a -iu > ${bed_id}_nearestExon.bed
+bedtools closest -a ${exons} -b ${bed} -D a -id >> ${bed_id}_nearestExon.bed
+bedtools sort -i ${bed_id}_nearestExon.bed > ${bed_id}_Distance_To_Exons_FasterDB_sorted.bed
 """
 }
\ No newline at end of file
diff --git a/src/test.nf b/src/test.nf
index 239e2873a082995b5350c801d961e9731b8eba86..693c16a230ef959e3f78762dcbaf49759805eaf7 100644
--- a/src/test.nf
+++ b/src/test.nf
@@ -14,7 +14,10 @@ Channel
 
 fastq_files = fastq1
     .concat(fastq2)
-    .groupBy
+    .set { fastq_files }
+
+println(fastq_files)
+
 
 /*
 idx_genome = "${params.idx}*.bt2"