Index: applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java
===================================================================
--- applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java	(revision 30789)
+++ applications/editors/josm/plugins/simplifyarea/src/sk/zdila/josm/plugin/simplify/SimplifyAreaAction.java	(revision 30791)
@@ -32,4 +32,5 @@
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
 import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.gui.HelpAwareOptionPane;
@@ -38,5 +39,5 @@
 import org.openstreetmap.josm.tools.Shortcut;
 
-public class SimplifyAreaAction extends JosmAction {
+public final class SimplifyAreaAction extends JosmAction {
 
     public SimplifyAreaAction() {
@@ -50,5 +51,5 @@
     }
 
-    private boolean isInBounds(final Node node, final List<Bounds> bounds) {
+    private static boolean isInBounds(final Node node, final List<Bounds> bounds) {
         for (final Bounds b : bounds) {
             if (b.contains(node.getCoor())) {
@@ -59,5 +60,5 @@
     }
 
-    private boolean confirmWayWithNodesOutsideBoundingBox() {
+    private static boolean confirmWayWithNodesOutsideBoundingBox() {
         final ButtonSpec[] options = new ButtonSpec[] { new ButtonSpec(tr("Yes, delete nodes"), ImageProvider.get("ok"), tr("Delete nodes outside of downloaded data regions"), null),
                 new ButtonSpec(tr("No, abort"), ImageProvider.get("cancel"), tr("Cancel operation"), null) };
@@ -175,6 +176,23 @@
     }
 
+    private static boolean nodeGluesWays(final Node node) {
+        Set<Node> referenceNeighbours = null;
+        for (final OsmPrimitive ref : node.getReferrers()) {
+            if (ref.getType() == OsmPrimitiveType.WAY) {
+                final Way way = ((Way) ref);
+                final Set<Node> neighbours = way.getNeighbours(node);
+                if (referenceNeighbours == null) {
+                    referenceNeighbours = neighbours;
+                } else if (!referenceNeighbours.containsAll(neighbours)) {
+                    return true;
+                }
+            }
+        }
+        
+        return false;
+    }
+
     // average nearby nodes
-    private Collection<Command> averageNearbyNodes(final Collection<Way> ways, final Collection<Node> nodesAlreadyDeleted) {
+    private static Collection<Command> averageNearbyNodes(final Collection<Way> ways, final Collection<Node> nodesAlreadyDeleted) {
         final double mergeThreshold = Main.pref.getDouble(SimplifyAreaPreferenceSetting.MERGE_THRESHOLD, 0.2);
 
@@ -200,5 +218,5 @@
 
             while (true) {
-                double minDist = Double.MAX_VALUE;
+                double minDist = Double.POSITIVE_INFINITY;
                 Node node1 = null;
                 Node node2 = null;
@@ -299,5 +317,5 @@
     }
 
-    private void addNodesToDelete(final Collection<Node> nodesToDelete, final Way w) {
+    private static void addNodesToDelete(final Collection<Node> nodesToDelete, final Way w) {
         final double angleThreshold = Main.pref.getDouble(SimplifyAreaPreferenceSetting.ANGLE_THRESHOLD, 10);
         final double angleFactor = Main.pref.getDouble(SimplifyAreaPreferenceSetting.ANGLE_FACTOR, 1.0);
@@ -333,5 +351,5 @@
             int prevIndex = -1;
 
-            double minWeight = Double.MAX_VALUE;
+            double minWeight = Double.POSITIVE_INFINITY;
             Node bestMatch = null;
 
@@ -357,5 +375,6 @@
 
                         weight = !closed && i == len - 1 || // don't remove last node of the not closed way
-                                angleWeight > 1.0 || areaWeight > 1.0 || distanceWeight > 1.0 ? Double.MAX_VALUE :
+                                nodeGluesWays(prevNode) ||
+                                angleWeight > 1.0 || areaWeight > 1.0 || distanceWeight > 1.0 ? Double.POSITIVE_INFINITY :
                                 angleWeight * angleFactor + areaWeight * areaFactor + distanceWeight * distanceFactor;
 
