diff --git a/containment/contents/code/LayoutManager.js b/containment/contents/code/LayoutManager.js
index 98c9677c6..72c42e4ff 100644
--- a/containment/contents/code/LayoutManager.js
+++ b/containment/contents/code/LayoutManager.js
@@ -151,6 +151,7 @@ function insertBefore(item1, item2) {
     for (var j = removed.length - 1; j >= 0; --j) {
         removed[j].parent = layout;
     }
+
     return i;
 }
 
@@ -188,6 +189,7 @@ function insertAfter(item1, item2) {
     for (var j = removed.length - 1; j >= 0; --j) {
         removed[j].parent = layout;
     }
+
     return i;
 }
 
@@ -254,18 +256,26 @@ function insertAtCoordinates(item, x, y) {
             }
         }
     }
+
     //already in position
     if (child === item) {
         return;
     }
+
     if (!child) {
-        child = layout.children[0];
+        // check if dragging takes place after the end of the layout
+        if ( ((root.isVertical && y > layout.height)||(root.Horizontal && x > layout.width))
+              && layout.children.length>0  ){
+            child = layout.children[layout.children.length-1];
+        } else {
+            child = layout.children[0];
+        }
+    } else {
+        item.parent = root;
     }
-    item.parent = root;
 
-    //PlasmaCore.Types.Vertical = 3
-    if ((plasmoid.formFactor === 3 && y < child.y + child.height/2) ||
-            (plasmoid.formFactor !== 3 && x < child.x + child.width/2)) {
+    if ((root.isVertical && y < child.y + child.height/2) ||
+            (root.isHorizontal && x < child.x + child.width/2)) {
         return insertBefore(child, item);
     } else {
         return insertAfter(child, item);
diff --git a/containment/contents/ui/main.qml b/containment/contents/ui/main.qml
index 9136d6607..d89d0f868 100644
--- a/containment/contents/ui/main.qml
+++ b/containment/contents/ui/main.qml
@@ -993,7 +993,7 @@ DragDrop.DropArea {
     Item {
         id: dndSpacer
 
-        property int normalSize: root.statesLineSizeOriginal + plasmoid.configuration.iconSize + root.iconMarginOriginal - 1
+        property int normalSize: visibilityManager.statesLineSizeOriginal + plasmoid.configuration.iconSize + visibilityManager.iconMarginOriginal - 1
 
         width: normalSize
         height: normalSize