diff --git a/usb_drive/insert_data.sh b/usb_drive/insert_data.sh
index a80f260fac31b21c90de8a1848ba0d5351f030a1..84398da5ab4bbec921dcb042d0dafc9b25723127 100755
--- a/usb_drive/insert_data.sh
+++ b/usb_drive/insert_data.sh
@@ -3,37 +3,40 @@ DIR_USB=/media/usb_drive/
 DIR_OPENSLX=/Openslx/
 user_name=`users |  cut -f 1 -d ' '`
 
+# prepares openslx partition to be used
+# mounts partition if not mounted
+# blocks program execution if it is not a openslx partition
+# param $1 is the devpath to be mounted
+# param $2 is the uuid of the partition
+# return is done via the mountpath global variable, which is also used here
 function prepare_usb {
-  # get the usb_drive's path
-  devpath=`readlink -f $usb_drives`
-  # check if the usb_drive is mounted
-  mount_msg=`mount | grep $devpath`
-  # if it is mounted, show the path
-  if [[ -n $mount_msg ]]; then
-    echo $mount_msg
-    mount_path=`mount | grep $devpath | cut -f 3 -d ' '`
-    counter=4
-    part_path=`mount | grep $devpath | cut -f 4 -d ' '`
-    while [ "$part_path" != "type" ];
-	do
-		mount_path=$mount_path"\ "$part_path
-		counter=$(($counter+1))
-		part_path=`mount | grep $devpath | cut -f $counter -d ' '`
-	done
-	echo $mount_path
-    echo $mount_path$DIR_OPENSLX
-    # If it is not mounted, mount it
+    # get the usb_drive's path
+    local devpath="/dev/"$1
+    mountpath=""
+    if [ ! 0 -eq $(mount | grep -q $devpath) ]; then
+        echo $0": Device $devpath is already mounted"
+        mountpath=$(mount | grep -w $devpath | cut -d' ' -f3)
     else
-      echo "$devpath não está montado";
-
-    if [ ! -d "$DIR_USB" ]; then
-        mkdir /media/usb_drive
-      echo "não existe"
+        echo $0": Device $devpath is not mounted"
+        mkdir -p /media/openslx/$2
+        if $(mount $devpath /media/openslx/$2); then
+            echo $0": Device $devpath mounted successfully"
+            mountpath="/media/openslx/"$2
+        else
+            echo $0": Device $devpath could not be mounted"
+            exit 1
+        fi
+    fi
+    if [ -e "$mountpath/Openslx/config" ]; then
+        echo $0": $devpath is an openslx ready drive"
+    else
+        echo $0": $devpath is not ready to be used as an openslx drive"
+        if [ $mountpath = "/media/openslx/$2" ]; then
+            echo $0": umounting $devpath"
+            umount $devpath
+        fi
+        exit 2
     fi
-    echo "Montando dispositivo..."
-    mount -o uid="$user_name" $devpath /media/usb_drive
-    mount_path=/media/usb_drive
-  fi
 }
 
 sleep 3