diff --git a/MAC/Tools/Power/poweruphba.sh b/MAC/Tools/Power/poweruphba.sh
index 02054bad3abf9abfa8465c18fc888fb5cd51c14f..7e80f990b9c8100445b158063802b385085ea8ce 100755
--- a/MAC/Tools/Power/poweruphba.sh
+++ b/MAC/Tools/Power/poweruphba.sh
@@ -1,63 +1,141 @@
 #!/bin/bash
 #
-# V3.1, M.J.Norden, 17-11-2015
-# usage: ./poweruphba.sh 5  (or 6 or 7)
-# Power up of the HBA Tiles needs to be slowed down because of high rush-in current. 
+# V4.0, A.P. Schoenmakers, 07-01-2016
+
+# usage: poweruphba.sh RCUMODE (5, 6 or 7) or
+#        poweruphba.sh [-a] -m RCUMODE (5, 6, or 7)
+#
+# Power up of the HBA Tiles. 
 # for rcumode 6 you need to switch the clock seperately (rspctl --clock=160)
 # from MAC version V2_12 and higher you can directly switch between rcumodes
 # The setting of hbadelays with 253 is needed for the new HBA-FE that are default off
 #
 # - automatic clock switch when needed
-# - automatic disble broken tiles from PVSS database
+# - optionally automatic disble broken tiles from PVSS database
 
+SyntaxError()
+{
+        Msg=$1
 
-clock=`rspctl --clock 2>&1|grep "Sample frequency"|sed -e 's/.*clock=\(...\)MHz/\1/'`
+        [ -z "${Msg}" ] || echo "ERROR: ${Msg}"
+        echo ""
+        echo "Syntax: $(basename $0) [-a] [-m RCU mode] or $(basename $0) [RCU mode]"
+        echo "-a: Power up all RCUs, do not check broken tile info"
+        echo "-m: RCU mode to use (5,6 or 7)"
+        echo ""
+        echo "If only one argument provided, that is interpreted as the requested RCU mode."
+	echo "No check for broken tile info will occur then."
+        echo ""
+        exit 0
+}
+
+HandleArgs()
+{
+  # Handle arguments
+  if [ "$#" -eq 0 ]; then
+    SyntaxError
+  fi
+
+  while getopts  "am:" flag
+    do
+      case "$flag" in
+      a)
+        checkbroken=0
+        ;;
+      m)
+        hbamode=$OPTARG	   
+        ;;
+      h)
+        SyntaxError
+        ;;
+      *)
+        SyntaxError
+        ;;
+      esac
+    done
+}
+
+# --- MAIN ---
 
-if [ "$1" != "" ]; then
-    if [ $1 -lt 5 ]; then
-       echo -e "Usage: ./poweruphba.sh 5 (or 6 or 7)\n"
-       exit  
-    elif [ $1 -gt 7 ]; then
-       echo -e "Usage: ./poweruphba.sh 5 (or 6 or 7)\n"
-       exit
-    else
-       if [ $clock = "160" ]; then
-         echo "wait 30 seconds for 200MHz clock switch"
-         rspctl --clock=200  
-         sleep 30
-       fi
-       hbamode=$1
-    fi
+# first check if swlevel < 6, otherwise this script will not funstion properly
+level=`swlevel -S`
+
+if [ $level -lt 2 -o $level -gt 5 ]; then 
+  echo "First set swlevel between 2 and 5 (current is $level)"
+  exit 0
+fi
+
+#Initialize parameters
+checkbroken=1
+hbamode=0
+
+if [ "$#" -eq 1 ]; then
+   hbamode=$1
+   checkbroken=0
 else 
-   echo -e "Usage: ./poweruphba.sh 5 (or 6 or 7)\n"
-   exit
+   HandleArgs $* 
+fi     
+
+
+if [ $hbamode -lt 5 -o $hbamode -gt 7 ]; then 
+   echo "RCUMode must be 5,6, or 7" 
+   exit 0
 fi
 
-if [ $hbamode -eq 6 ]; then
-    if [ $clock = "200" ]; then
-       echo "wait 30 seconds for 160MHz clock switch"
-       rspctl --clock=160
-       sleep 30
-    fi
-fi    
+# Find current clock setting
+clock=`rspctl --clock 2>&1|grep "Sample frequency"|sed -e 's/.*clock=\(...\)MHz/\1/'`
+
+# Set clock to proper value
+if [ $hbamode -eq 6 ]; then 
+   if [ "$clock" == "200" ]; then 
+      echo "wait 30 seconds for 160MHz clock switch"
+      rspctl --clock=160
+      sleep 30
+   fi
+else 
+   if [ "$clock" == "160" ]; then
+      echo "wait 30 seconds for 200MHz clock switch"
+      rspctl --clock=200  
+      sleep 30
+   fi
+fi 
+
+# Set selected mode and switch on HBAs
 rspctl --rcumode=$hbamode
 sleep 1
 rspctl --rcuenable=1
 sleep 1
 
-DISABLED_RCU_LIST=`/opt/lofar/sbin/disabledRCUlist $hbamode 2</dev/null` 
-if test "$DISABLED_RCU_LIST" == ""; then 
-   echo "no disabled HBA tiles" 
+# Determine broken tiles
+DISABLED_RCU_LIST=""
+if [ $checkbroken -eq 1 ]; then 
+   if [ -e /opt/lofar/sbin/disabledRCUlist ]; then  
+      DISABLED_RCU_LIST=`/opt/lofar/sbin/disabledRCUlist $hbamode 2</dev/null`
+   else
+      echo "Cannot determine broken RCUs; missing /opt/lofar/sbin/disabledRCUlist"
+   fi
+fi 
+
+# Switch off broken tiles (if any)
+if [ "$DISABLED_RCU_LIST" == "" ]; then 
+   echo "No disabled HBA tiles found" 
 else 
-   rspctl --rcumode=0 --sel=$DISABLED_RCU_LIST 
+   rspctl --rcumode=0 --select=$DISABLED_RCU_LIST 
    sleep 1
    rspctl --rcuenable=0 --select=$DISABLED_RCU_LIST 
    sleep 1
 fi
+
+# Set delay values
 rspctl --hbadelays=253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253
+sleep 1
 
+# Set spectral Inversion properly
 if [ $hbamode -eq 5 ]; then 
    rspctl --specinv=1
 else
    rspctl --specinv=0
 fi
+sleep 1
+
+echo "Done"