diff --git a/validate_workflow.sh b/validate_workflow.sh
index 726fe6639a4eec85bd7ba2ca0b74cc912e0d072d..52e230e12a7d96cff6e244fb1aee8f3d08312f6d 100755
--- a/validate_workflow.sh
+++ b/validate_workflow.sh
@@ -44,7 +44,7 @@
 #hh      -s, --statistics
 #hh                 print a statistic
 #hh      -m, --mode [auto, mediathek, fotothek, save, kitodo, lfulg]
-#hh                the mode 'auto' tries to check files based on file extensions.
+#hh                the mode 'auto' tries to check files based on file mime-types.
 #hh                The other modes are actual workflow names.
 #hh      -d, --daemon
 #hh                starts a daemon, works only in --files-mode=delete
@@ -109,9 +109,14 @@ calc_statistics() {
 }
 
 print_statistics() {
+    local stat
+    local cnt_total
+    local cnt_valid
+    local cnt_invalid
+    local ratio
     stat=$(calc_statistics)
-    cnt_total=$(echo $stat | awk 'END {print $1}')
-    cnt_valid=$(echo $stat | awk 'END {print $2}')
+    cnt_total=$(echo "$stat" | awk 'END {print $1}')
+    cnt_valid=$(echo "$stat" | awk 'END {print $2}')
     cnt_invalid=$((cnt_total - cnt_valid))
     ratio=$(( 100*cnt_valid / cnt_total ))
     echo "Validation Statistics"
@@ -122,11 +127,12 @@ print_statistics() {
 }
 
 update_statistics() {
-    is_valid=$1
-    duration=$2
-    ftype=$3
-    workflow=$4
-    stage=$5
+    local is_valid=$1
+    local duration=$2
+    local ftype=$3
+    local workflow=$4
+    local stage=$5
+    local date
     date=$(date +"%F%T")
     debug "date=$date"
     flock -x $LOCKFILE echo "$date,$is_valid,$duration,$ftype,$workflow,$stage" >> "$STATFILE"
@@ -149,13 +155,16 @@ error() {
 }
 
 get_mimetype() {
-    filename=$1
+    local filename=$1
+    local res
     res=$(file --mime-type "$filename" |  sed -e "s/^.*: //")
     echo "$res"
 }
 
 
-get_cli_args() { 
+get_cli_args() {
+    local lines
+    local cachedir
     while [[ $# -gt 0 ]]; do
         case ${1} in
             -h | --help)
@@ -235,10 +244,10 @@ get_cli_args() {
     if [ "$WITH_PIPE" -eq 1 ]; then
         if 
             [ "$WITH_DAEMON" -eq 1 ] \
-            || [ "$WATCH_FOLDER" ] \
-            || [ "$RESULT_FOLDER" ] \
-            || [ "$VALID_FOLDER" ] \
-            || [ "$INVALID_FOLDER" ] \
+            || [ -n "$WATCH_FOLDER" ] \
+            || [ -n "$RESULT_FOLDER" ] \
+            || [ -n "$VALID_FOLDER" ] \
+            || [ -n "$INVALID_FOLDER" ] \
             || [ "$FILES_MODE" = "sort" ] \
             ; then 
             error "param --pipe not combineable with params --daemon, --result-folder, --watch-folder, --valid-folder, --invalid-folder, --files-mode"
@@ -289,9 +298,11 @@ get_cli_args() {
 }
 
 prepare_cmd() {
-    mode=$1
-    ftype=$2
-    stage=$3
+    local mode=$1
+    local ftype=$2
+    local stage=$3
+    local key
+    local cmd
     key=$(printf "%11s%4s%9s" "$mode" "$ftype" "$stage"|sed -e "y/ /_/")
     debug "prepare_cmd, key=$key"
     if [[ ${validators[$key]:+1} ]]; then
@@ -304,7 +315,8 @@ prepare_cmd() {
 }
 
 prepare_ftype() {
-    mimetype=$1
+    local mimetype=$1
+    local ftype
     debug "prepare_ftype, using mimetype: $mimetype"
     case ${mimetype} in
         "image/tiff")
@@ -323,7 +335,7 @@ prepare_ftype() {
 }
 
 estimate_mode() {
-    mimetype=$1
+    local mimetype=$1
     debug "estimate_mode, using mimetype: $mimetype"
     case ${mimetype} in
         "image/tiff")
@@ -338,29 +350,31 @@ estimate_mode() {
             ;;
     esac
     debug "estimate_mode, detected mode: $MODE"
-    echo $MODE
+    echo "$MODE"
 }
 
 exec_cmd() {
-    cmd=$1
-    ftype=$2
-    workflow=$3
-    stage=$4
-    log=$5
+    local cmd=$1
+    local ftype=$2
+    local workflow=$3
+    local stage=$4
+    local log=$5
+    local start_t
+    local stop_t
     start_t=$(date +"%s")
     debug "scan_file, calling cmd='$cmd'"
     $cmd >>"$log" 2>&1
-    is_valid=$?
+    local is_valid=$?
     stop_t=$(date +"%s")
-    duration=$((stop_t - start_t))
+    local duration=$((stop_t - start_t))
     debug "scan_file, duration=$duration is_valid=$is_valid log=$log"
     update_statistics "$is_valid" "$duration" "$ftype" "$workflow" "$stage"
     echo "$is_valid"
 }
 
 handle_input_if_requested() {
-    filename=$1
-    is_valid=$2
+    local filename=$1
+    local is_valid=$2
     debug "handle_input_if_requested, filename=$filename is_valid=$is_valid"
     if [ "$FILES_MODE" = "sort" ]; then
         if [ "$is_valid" -eq 0 ]; then
@@ -377,7 +391,8 @@ handle_input_if_requested() {
 }
 
 get_logfile() {
-    filename=$1
+    local filename=$1
+    local logname
     logname=$(echo "$filename"| sed -e "s#^${WATCH_FOLDER}#${RESULT_FOLDER}#"  -e "s#\$#.log#")
     debug "get_logfile, logname=$logname (filename=$filename)"
     echo "$logname"
@@ -385,7 +400,12 @@ get_logfile() {
 
 
 scan_file() {
-    filename="$1"
+    local filename="$1"
+    local mimetype
+    local ftype
+    local logname
+    local cmd
+    local is_valid
     debug "scan_file, using filename: $filename"
     mimetype=$(get_mimetype "$filename")
     ftype=$(prepare_ftype "$mimetype")