Index: trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 3594)
+++ trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java	(revision 3595)
@@ -501,27 +501,32 @@
         List<AssembledMultipolygon> preparedPolygons = findPolygons(bounadries);
 
-        //assemble final ways
+        //assemble final polygons
         List<Multipolygon> polygons = new ArrayList<Multipolygon>();
         for (AssembledMultipolygon pol : preparedPolygons) {
-            polygons.add(joinPolygon(pol));
-        }
+
+            //create the new ways
+            Multipolygon resultPol = joinPolygon(pol);
+
+            //create multipolygon relation, if necessary.
+            RelationRole ownMultipolygonRelation = addOwnMultigonRelation(resultPol.innerWays, resultPol.outerWay);
+
+            //add back the original relations, merged with our new multipolygon relation
+            fixRelations(relations, resultPol.outerWay, ownMultipolygonRelation);
+
+            //strip tags from inner ways
+            //TODO: preserve tags on existing inner ways
+            stripTags(resultPol.innerWays);
+
+            polygons.add(resultPol);
+        }
+
+        commitCommands(marktr("Assemble new polygons"));
 
         // Delete the discarded inner ways
         if (discardedWays.size() > 0) {
             cmds.add(DeleteCommand.delete(Main.map.mapView.getEditLayer(), discardedWays, true));
-        }
-        commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
-
-        // We can attach our new multipolygon relation and pretend it has always been there
-        for (Multipolygon pol : polygons) {
-            addOwnMultigonRelation(pol.innerWays, pol.outerWay, relations);
-            fixRelations(relations, pol.outerWay);
-        }
-
-        commitCommands(marktr("Fix relations"));
-
-        for (Multipolygon pol : polygons) {
-            stripTags(pol.innerWays);
-        }
+            commitCommands(marktr("Delete Ways that are not part of an inner multipolygon"));
+        }
+
 
         makeCommitsOneAction(marktr("Joined overlapping areas"));
@@ -1630,6 +1635,6 @@
      * @param ArrayList<RelationRole> The list of relation with roles to add own relation to
      */
-    private void addOwnMultigonRelation(Collection<Way> inner, Way outer, ArrayList<RelationRole> rels) {
-        if (inner.size() == 0) return;
+    private RelationRole addOwnMultigonRelation(Collection<Way> inner, Way outer) {
+        if (inner.size() == 0) return null;
         // Create new multipolygon relation and add all inner ways to it
         Relation newRel = new Relation();
@@ -1641,8 +1646,6 @@
 
         // We don't add outer to the relation because it will be handed to fixRelations()
-        // which will then do the remaining work. Collections are passed by reference, so no
-        // need to return it
-        rels.add(new RelationRole(newRel, "outer"));
-        //return rels;
+        // which will then do the remaining work.
+        return new RelationRole(newRel, "outer");
     }
 
@@ -1691,6 +1694,11 @@
      * @param Way The newly created outer area/way
      */
-    private void fixRelations(ArrayList<RelationRole> rels, Way outer) {
+    private void fixRelations(ArrayList<RelationRole> rels, Way outer, RelationRole ownMultipol) {
         ArrayList<RelationRole> multiouters = new ArrayList<RelationRole>();
+
+        if (ownMultipol != null){
+            multiouters.add(ownMultipol);
+        }
+
         for (RelationRole r : rels) {
             if (r.rel.get("type") != null &&
