Index: trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/AddNodeAction.java	(revision 12726)
@@ -12,4 +12,5 @@
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -66,6 +67,7 @@
 
         // add the node
-        MainApplication.undoRedo.add(new AddCommand(nnew));
-        getLayerManager().getEditDataSet().setSelected(nnew);
+        DataSet ds = getLayerManager().getEditDataSet();
+        MainApplication.undoRedo.add(new AddCommand(ds, nnew));
+        ds.setSelected(nnew);
         MapView mapView = MainApplication.getMap().mapView;
         if (mapView != null && !mapView.getRealBounds().contains(nnew.getCoor())) {
Index: trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java	(revision 12726)
@@ -25,4 +25,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -137,5 +138,6 @@
         }
 
-        Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getSelected();
+        DataSet ds = getLayerManager().getEditDataSet();
+        Collection<OsmPrimitive> sel = ds.getSelected();
         List<Node> nodes = OsmPrimitive.getFilteredList(sel, Node.class);
         List<Way> ways = OsmPrimitive.getFilteredList(sel, Way.class);
@@ -222,5 +224,5 @@
                 Node n = new Node(ll);
                 nodesToAdd.add(n);
-                cmds.add(new AddCommand(n));
+                cmds.add(new AddCommand(ds, n));
             }
         }
@@ -234,9 +236,9 @@
             Way newWay = new Way();
             newWay.setNodes(nodesToAdd);
-            cmds.add(new AddCommand(newWay));
+            cmds.add(new AddCommand(ds, newWay));
         } else {
             Way newWay = new Way(existingWay);
             newWay.setNodes(nodesToAdd);
-            cmds.add(new ChangeCommand(existingWay, newWay));
+            cmds.add(new ChangeCommand(ds, existingWay, newWay));
         }
 
Index: trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java	(revision 12726)
@@ -248,5 +248,5 @@
         final String commandName;
         if (existingRelation == null) {
-            list.add(new AddCommand(relation));
+            list.add(new AddCommand(selectedWays.iterator().next().getDataSet(), relation));
             commandName = getName(false);
         } else {
Index: trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java	(revision 12726)
@@ -15,4 +15,5 @@
 import org.openstreetmap.josm.command.SelectCommand;
 import org.openstreetmap.josm.command.SequenceCommand;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -20,5 +21,4 @@
 import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.Shortcut;
 import org.openstreetmap.josm.tools.Utils;
@@ -61,12 +61,12 @@
     @Override
     public void actionPerformed(ActionEvent evt) {
-        OsmDataLayer osmLayer = getLayerManager().getEditLayer();
-        if (osmLayer == null)
+        DataSet ds = getLayerManager().getEditDataSet();
+        if (ds == null)
             return;
         MapFrame map = MainApplication.getMap();
         if (!(map.mapMode instanceof DrawAction)) return; // We are not on draw mode
 
-        Collection<Node> selectedPoints = osmLayer.data.getSelectedNodes();
-        Collection<Way> selectedLines = osmLayer.data.getSelectedWays();
+        Collection<Node> selectedPoints = ds.getSelectedNodes();
+        Collection<Way> selectedLines = ds.getSelectedWays();
         if ((selectedPoints.size() > 1) || (selectedLines.size() != 1)) // Unsuitable selection
             return;
@@ -115,6 +115,6 @@
             }
             MainApplication.undoRedo.add(new SequenceCommand(tr("Follow line"),
-                    new ChangeCommand(follower, newFollower),
-                    new SelectCommand(newFollower.isClosed() // see #10028 - unselect last node when closing a way
+                    new ChangeCommand(ds, follower, newFollower),
+                    new SelectCommand(ds, newFollower.isClosed() // see #10028 - unselect last node when closing a way
                             ? Arrays.<OsmPrimitive>asList(follower)
                             : Arrays.<OsmPrimitive>asList(follower, newPoint)
Index: trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java	(revision 12726)
@@ -24,4 +24,5 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -84,11 +85,11 @@
         if (!isEnabled())
             return;
-        Collection<Node> selectedNodes = getLayerManager().getEditDataSet().getSelectedNodes();
+        DataSet ds = getLayerManager().getEditDataSet();
+        Collection<Node> selectedNodes = ds.getSelectedNodes();
         Collection<Command> cmds = new LinkedList<>();
         Map<Way, MultiMap<Integer, Node>> data = new HashMap<>();
 
         // If the user has selected some ways, only join the node to these.
-        boolean restrictToSelectedWays =
-                !getLayerManager().getEditDataSet().getSelectedWays().isEmpty();
+        boolean restrictToSelectedWays = !ds.getSelectedWays().isEmpty();
 
         // Planning phase: decide where we'll insert the nodes and put it all in "data"
@@ -155,5 +156,5 @@
             Way wnew = new Way(w);
             wnew.setNodes(wayNodes);
-            cmds.add(new ChangeCommand(w, wnew));
+            cmds.add(new ChangeCommand(ds, w, wnew));
         }
 
Index: trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java	(revision 12726)
@@ -157,5 +157,5 @@
             corrCmds = (new ReverseWayTagCorrector()).execute(w, wnew);
         }
-        return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w.getDataSet(), w, wnew));
+        return new ReverseWayResult(wnew, corrCmds, new ChangeCommand(w, wnew));
     }
 
Index: trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java	(revision 12726)
@@ -593,5 +593,5 @@
         final Way changedWay = new Way(way);
         changedWay.setNodes(wayToKeep.getNodes());
-        commandList.add(new ChangeCommand(way.getDataSet(), way, changedWay));
+        commandList.add(new ChangeCommand(way, changedWay));
         if (!isMapModeDraw && !newSelection.contains(way)) {
             newSelection.add(way);
Index: trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java	(revision 12726)
@@ -303,5 +303,5 @@
 
         List<Command> cmds = new LinkedList<>();
-        cmds.add(new AddCommand(n));
+        cmds.add(new AddCommand(selectedNode.getDataSet(), n));
         if (dialog != null) {
             dialog.update(selectedNode, Collections.singletonList(n), cmds);
@@ -440,5 +440,5 @@
         Node newNode = new Node(originalNode, true /* clear OSM ID */);
         newNodes.add(newNode);
-        cmds.add(new AddCommand(newNode));
+        cmds.add(new AddCommand(originalNode.getDataSet(), newNode));
 
         List<Node> nn = new ArrayList<>();
@@ -583,5 +583,5 @@
                 if (seen) {
                     Node newNode = new Node(n, true /* clear OSM ID */);
-                    cmds.add(new AddCommand(newNode));
+                    cmds.add(new AddCommand(selectedNode.getDataSet(), newNode));
                     newNodes.add(newNode);
                     addNodes.add(newNode);
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java	(revision 12726)
@@ -487,5 +487,5 @@
                 return;
             }
-            cmds.add(new AddCommand(n));
+            cmds.add(new AddCommand(ds, n));
 
             if (!ctrl) {
@@ -576,5 +576,5 @@
                     way = new Way();
                     way.addNode(n0);
-                    cmds.add(new AddCommand(way));
+                    cmds.add(new AddCommand(ds, way));
                     wayToSelect = way;
                 } else {
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java	(revision 12726)
@@ -40,4 +40,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -592,7 +593,7 @@
             Way wnew = new Way(ws.way);
             wnew.addNode(ws.lowerIndex+1, n);
-            SequenceCommand cmds = new SequenceCommand(tr("Add a new node to an existing way"),
-                    new AddCommand(n), new ChangeCommand(ws.way, wnew));
-            MainApplication.undoRedo.add(cmds);
+            DataSet ds = ws.way.getDataSet();
+            MainApplication.undoRedo.add(new SequenceCommand(tr("Add a new node to an existing way"),
+                    new AddCommand(ds, n), new ChangeCommand(ds, ws.way, wnew)));
         }
     }
@@ -603,5 +604,6 @@
     private void createNewRectangle() {
         if (selectedSegment == null) return;
-        // crete a new rectangle
+        DataSet ds = getLayerManager().getEditDataSet();
+        // create a new rectangle
         Collection<Command> cmds = new LinkedList<>();
         Node third = new Node(newN2en);
@@ -618,12 +620,12 @@
         wnew.addNode(selectedSegment.getFirstNode());
         // undo support
-        cmds.add(new AddCommand(third));
+        cmds.add(new AddCommand(ds, third));
         if (!dualAlignSegmentCollapsed) {
-            cmds.add(new AddCommand(fourth));
-        }
-        cmds.add(new AddCommand(wnew));
+            cmds.add(new AddCommand(ds, fourth));
+        }
+        cmds.add(new AddCommand(ds, wnew));
         Command c = new SequenceCommand(tr("Extrude Way"), cmds);
         MainApplication.undoRedo.add(c);
-        getLayerManager().getEditDataSet().setSelected(wnew);
+        ds.setSelected(wnew);
     }
 
@@ -634,4 +636,5 @@
      */
     private void performExtrusion() {
+        DataSet ds = getLayerManager().getEditDataSet();
         // create extrusion
         Collection<Command> cmds = new LinkedList<>();
@@ -661,5 +664,5 @@
             wnew.removeNode(n1Old);
             wayWasModified = true;
-            cmds.add(new AddCommand(n1New));
+            cmds.add(new AddCommand(ds, n1New));
             changedNodes.add(n1New);
         } else {
@@ -669,5 +672,5 @@
             wayWasModified = true;
             insertionPoint++;
-            cmds.add(new AddCommand(n1New));
+            cmds.add(new AddCommand(ds, n1New));
             changedNodes.add(n1New);
         }
@@ -691,5 +694,5 @@
             wnew.removeNode(n2Old);
             wayWasModified = true;
-            cmds.add(new AddCommand(n2New));
+            cmds.add(new AddCommand(ds, n2New));
             changedNodes.add(n2New);
         } else {
@@ -698,5 +701,5 @@
             wnew.addNode(insertionPoint, n2New);
             wayWasModified = true;
-            cmds.add(new AddCommand(n2New));
+            cmds.add(new AddCommand(ds, n2New));
             changedNodes.add(n2New);
         }
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java	(revision 12726)
@@ -399,4 +399,5 @@
         }
 
+        DataSet ds = getLayerManager().getEditDataSet();
         updateKeyModifiers(e);
         mousePos = e.getPoint();
@@ -404,5 +405,5 @@
         if (state == State.SELECTING) {
             if (targetWay != null) {
-                getLayerManager().getEditDataSet().setSelected(targetWay.getPrimitiveId());
+                ds.setSelected(targetWay.getPrimitiveId());
                 updateStateByCurrentSelection();
             }
@@ -425,5 +426,5 @@
                 Node virtualNode = new Node(mv.getEastNorth(mousePos.x,
                         mousePos.y));
-                virtualCmds.add(new AddCommand(virtualNode));
+                virtualCmds.add(new AddCommand(ds, virtualNode));
 
                 // Looking for candidateSegment copies in ways that are
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java	(revision 12726)
@@ -11,8 +11,10 @@
 import java.util.Set;
 
+import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.EastNorth;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.NodeGraph;
@@ -186,10 +188,11 @@
 
     private List<Command> makeAddWayAndNodesCommandList() {
+        DataSet ds = Main.main.getEditDataSet();
         List<Command> commands = new ArrayList<>(sortedNodes.size() + ways.size());
         for (int i = 0; i < sortedNodes.size() - (isClosedPath() ? 1 : 0); i++) {
-            commands.add(new AddCommand(sortedNodes.get(i)));
+            commands.add(new AddCommand(ds, sortedNodes.get(i)));
         }
         for (Way w : ways) {
-            commands.add(new AddCommand(w));
+            commands.add(new AddCommand(ds, w));
         }
         return commands;
Index: trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java	(revision 12726)
@@ -1235,11 +1235,12 @@
 
         private void createMiddleNodeFromVirtual(EastNorth currentEN) {
+            DataSet ds = getLayerManager().getEditDataSet();
             Collection<Command> virtualCmds = new LinkedList<>();
-            virtualCmds.add(new AddCommand(virtualNode));
+            virtualCmds.add(new AddCommand(ds, virtualNode));
             for (WaySegment virtualWay : virtualWays) {
                 Way w = virtualWay.way;
                 Way wnew = new Way(w);
                 wnew.addNode(virtualWay.lowerIndex + 1, virtualNode);
-                virtualCmds.add(new ChangeCommand(w, wnew));
+                virtualCmds.add(new ChangeCommand(ds, w, wnew));
             }
             virtualCmds.add(new MoveCommand(virtualNode, startEN, currentEN));
@@ -1248,5 +1249,5 @@
                     virtualWays.size());
             MainApplication.undoRedo.add(new SequenceCommand(text, virtualCmds));
-            getLayerManager().getEditDataSet().setSelected(Collections.singleton((OsmPrimitive) virtualNode));
+            ds.setSelected(Collections.singleton((OsmPrimitive) virtualNode));
             clear();
         }
Index: trunk/src/org/openstreetmap/josm/command/AddCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/AddCommand.java	(revision 12726)
@@ -36,5 +36,7 @@
      * Creates the command and specify the element to add in the context of the current edit layer, if any.
      * @param osm The primitive to add
+     * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead
      */
+    @Deprecated
     public AddCommand(OsmPrimitive osm) {
         this.osm = Objects.requireNonNull(osm, "osm");
Index: trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java	(revision 12726)
@@ -39,5 +39,7 @@
      * Constructs a new {@code AddPrimitivesCommand} to add data to the current edit layer.
      * @param data The OSM primitives data to add. Must not be {@code null}
-     */
+     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, DataSet)} instead
+     */
+    @Deprecated
     public AddPrimitivesCommand(List<PrimitiveData> data) {
         this(data, data);
@@ -49,5 +51,7 @@
      * @param toSelect The OSM primitives to select at the end. Can be {@code null}
      * @since 5953
-     */
+     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead
+     */
+    @Deprecated
     public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect) {
         init(data, toSelect);
@@ -77,4 +81,14 @@
         super(ds);
         init(data, toSelect);
+    }
+
+    /**
+     * Constructs a new {@code AddPrimitivesCommand} to add data to the given data set.
+     * @param data The OSM primitives data to add and select. Must not be {@code null}
+     * @param ds The target data set. Must not be {@code null}
+     * @since 12726
+     */
+    public AddPrimitivesCommand(List<PrimitiveData> data, DataSet ds) {
+        this(data, data, ds);
     }
 
Index: trunk/src/org/openstreetmap/josm/command/ChangeCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/ChangeCommand.java	(revision 12726)
@@ -30,12 +30,10 @@
 
     /**
-     * Constructs a new {@code ChangeCommand} in the context of the current edit layer, if any.
-     * @param osm The existing primitive to modify
+     * Constructs a new {@code ChangeCommand} in the context of {@code osm} data set.
+     * @param osm The existing primitive to modify. It must belong to a data set
      * @param newOsm The new primitive
      */
     public ChangeCommand(OsmPrimitive osm, OsmPrimitive newOsm) {
-        this.osm = osm;
-        this.newOsm = newOsm;
-        sanityChecks();
+        this(osm.getDataSet(), osm, newOsm);
     }
 
Index: trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/ChangeNodesCommand.java	(revision 12726)
@@ -10,4 +10,5 @@
 import javax.swing.Icon;
 
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
 import org.openstreetmap.josm.data.osm.Node;
@@ -36,4 +37,16 @@
      */
     public ChangeNodesCommand(Way way, List<Node> newNodes) {
+        this(way.getDataSet(), way, newNodes);
+    }
+
+    /**
+     * Constructs a new {@code ChangeNodesCommand}.
+     * @param ds The target data set. Must not be {@code null}
+     * @param way The way to modify
+     * @param newNodes The new list of nodes for the given way
+     * @since 12726
+     */
+    public ChangeNodesCommand(DataSet ds, Way way, List<Node> newNodes) {
+        super(ds);
         this.way = way;
         this.newNodes = newNodes;
Index: trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java	(revision 12726)
@@ -13,4 +13,5 @@
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -72,8 +73,11 @@
      * Creates a command to change multiple tags of multiple objects
      *
-     * @param objects the objects to modify
+     * @param ds The target data set. Must not be {@code null}
+     * @param objects the objects to modify. Must not be empty
      * @param tags the tags to set
-     */
-    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
+     * @since 12726
+     */
+    public ChangePropertyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
+        super(ds);
         this.tags = tags;
         init(objects);
@@ -81,11 +85,26 @@
 
     /**
+     * Creates a command to change multiple tags of multiple objects
+     *
+     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
+     * @param tags the tags to set
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
+     */
+    public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, Map<String, String> tags) {
+        this(objects.iterator().next().getDataSet(), objects, tags);
+    }
+
+    /**
      * Creates a command to change one tag of multiple objects
      *
-     * @param objects the objects to modify
+     * @param objects the objects to modify. Must not be empty, and objects must belong to a data set
      * @param key the key of the tag to set
      * @param value the value of the key to set
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public ChangePropertyCommand(Collection<? extends OsmPrimitive> objects, String key, String value) {
+        super(objects.iterator().next().getDataSet());
         this.tags = new HashMap<>(1);
         this.tags.put(key, value);
@@ -96,7 +115,8 @@
      * Creates a command to change one tag of one object
      *
-     * @param object the object to modify
+     * @param object the object to modify. Must belong to a data set
      * @param key the key of the tag to set
      * @param value the value of the key to set
+     * @throws NullPointerException if object is null
      */
     public ChangePropertyCommand(OsmPrimitive object, String key, String value) {
@@ -134,6 +154,4 @@
     @Override
     public boolean executeCommand() {
-        if (objects.isEmpty())
-            return true;
         final DataSet dataSet = objects.get(0).getDataSet();
         if (dataSet != null) {
Index: trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/ChangePropertyKeyCommand.java	(revision 12726)
@@ -10,8 +10,10 @@
 import java.util.LinkedList;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 
 import javax.swing.Icon;
 
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.validation.util.NameVisitor;
@@ -66,5 +68,5 @@
      * Constructs a new {@code ChangePropertyKeyCommand}.
      *
-     * @param object the object subject to change replacement
+     * @param object the object subject to change replacement. Must not be null, and belong to a data set
      * @param key The key to replace
      * @param newKey the new value of the key
@@ -78,9 +80,25 @@
      * Constructs a new {@code ChangePropertyKeyCommand}.
      *
-     * @param objects all objects subject to change replacement
+     * @param objects all objects subject to change replacement. Must not be null or empty, and objects must belong to a data set
      * @param key The key to replace
      * @param newKey the new value of the key
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public ChangePropertyKeyCommand(Collection<? extends OsmPrimitive> objects, String key, String newKey) {
+        this(objects.iterator().next().getDataSet(), objects, key, newKey);
+    }
+
+    /**
+     * Constructs a new {@code ChangePropertyKeyCommand}.
+     *
+     * @param ds The target data set. Must not be {@code null}
+     * @param objects all objects subject to change replacement.
+     * @param key The key to replace
+     * @param newKey the new value of the key
+     * @since 12726
+     */
+    public ChangePropertyKeyCommand(DataSet ds, Collection<? extends OsmPrimitive> objects, String key, String newKey) {
+        super(ds);
         this.objects = new LinkedList<>(objects);
         this.key = key;
Index: trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/ChangeRelationMemberRoleCommand.java	(revision 12726)
@@ -37,17 +37,15 @@
     /**
      * Constructs a new {@code ChangeRelationMemberRoleCommand}.
-     * @param relation The relation to be changed
+     * @param relation The relation to be changed. Must not be null, and belong to a data set
      * @param position Member position
      * @param newRole New role
      */
     public ChangeRelationMemberRoleCommand(Relation relation, int position, String newRole) {
-        this.relation = relation;
-        this.position = position;
-        this.newRole = newRole;
+        this(relation.getDataSet(), relation, position, newRole);
     }
 
     /**
      * Constructs a new {@code ChangeRelationMemberRoleCommand}.
-     * @param dataSet The data set the role is in
+     * @param dataSet The data set the role is in. Must not be {@code null}
      * @param relation The relation to be changed
      * @param position Member position
Index: trunk/src/org/openstreetmap/josm/command/Command.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/Command.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/Command.java	(revision 12726)
@@ -147,5 +147,7 @@
     /**
      * Creates a new command in the context of the current edit layer, if any
-     */
+     * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead
+     */
+    @Deprecated
     public Command() {
         this.layer = MainApplication.getLayerManager().getEditLayer();
Index: trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/DeleteCommand.java	(revision 12726)
@@ -75,5 +75,5 @@
         @Override
         public String toString() {
-            return "DeleteChildCommand [osm=" + osm + "]";
+            return "DeleteChildCommand [osm=" + osm + ']';
         }
     }
@@ -88,11 +88,9 @@
      * Constructor. Deletes a collection of primitives in the current edit layer.
      *
-     * @param data the primitives to delete. Must neither be null nor empty.
+     * @param data the primitives to delete. Must neither be null nor empty, and belong to a data set
      * @throws IllegalArgumentException if data is null or empty
      */
     public DeleteCommand(Collection<? extends OsmPrimitive> data) {
-        CheckParameterUtil.ensureParameterNotNull(data, "data");
-        this.toDelete = data;
-        checkConsistency();
+        this(data.iterator().next().getDataSet(), data);
     }
 
Index: trunk/src/org/openstreetmap/josm/command/MoveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/MoveCommand.java	(revision 12726)
@@ -9,4 +9,5 @@
 import java.util.LinkedList;
 import java.util.List;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 
@@ -84,9 +85,12 @@
     /**
      * Constructs a new {@code MoveCommand} and assign the initial object set and movement vector.
-     * @param objects The primitives to move
+     * @param objects The primitives to move. Must neither be null nor empty. Objects must belong to a data set
      * @param x X difference movement. Coordinates are in northern/eastern
      * @param y Y difference movement. Coordinates are in northern/eastern
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public MoveCommand(Collection<OsmPrimitive> objects, double x, double y) {
+        super(objects.iterator().next().getDataSet());
         startEN = null;
         saveCheckpoint(); // (0,0) displacement will be saved
Index: trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/RemoveNodesCommand.java	(revision 12726)
@@ -33,8 +33,9 @@
     /**
      * Constructs a new {@code RemoveNodesCommand}.
-     * @param way The way to modify
+     * @param way The way to modify. Must not be null, and belong to a data set
      * @param rmNodes The list of nodes to remove
      */
     public RemoveNodesCommand(Way way, List<Node> rmNodes) {
+        super(way.getDataSet());
         this.way = way;
         this.rmNodes = new HashSet<>(rmNodes);
Index: trunk/src/org/openstreetmap/josm/command/SelectCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/SelectCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/SelectCommand.java	(revision 12726)
@@ -28,5 +28,7 @@
      * Constructs a new select command.
      * @param newSelection the primitives to select when executing the command.
+     * @deprecated to be removed end of 2017. Use {@link #SelectCommand(DataSet, Collection)} instead
      */
+    @Deprecated
     public SelectCommand(Collection<OsmPrimitive> newSelection) {
         if (newSelection == null || newSelection.isEmpty()) {
Index: trunk/src/org/openstreetmap/josm/command/SequenceCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/SequenceCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/SequenceCommand.java	(revision 12726)
@@ -11,4 +11,5 @@
 import javax.swing.Icon;
 
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.layer.Layer;
@@ -33,4 +34,19 @@
     /**
      * Create the command by specifying the list of commands to execute.
+     * @param ds The target data set. Must not be {@code null}
+     * @param name The description text
+     * @param sequenz The sequence that should be executed
+     * @param continueOnError Determines if the sequence execution should continue after one of its commands fails
+     * @since 12726
+     */
+    public SequenceCommand(DataSet ds, String name, Collection<Command> sequenz, boolean continueOnError) {
+        super(ds);
+        this.name = name;
+        this.sequence = sequenz.toArray(new Command[sequenz.size()]);
+        this.continueOnError = continueOnError;
+    }
+
+    /**
+     * Create the command by specifying the list of commands to execute.
      * @param name The description text
      * @param sequenz The sequence that should be executed. Must not be null or empty
@@ -39,8 +55,5 @@
      */
     public SequenceCommand(String name, Collection<Command> sequenz, boolean continueOnError) {
-        super(sequenz.iterator().next().getAffectedDataSet());
-        this.name = name;
-        this.sequence = sequenz.toArray(new Command[sequenz.size()]);
-        this.continueOnError = continueOnError;
+        this(sequenz.iterator().next().getAffectedDataSet(), name, sequenz, continueOnError);
     }
 
Index: trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/TransformNodesCommand.java	(revision 12726)
@@ -6,6 +6,6 @@
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.LinkedList;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.Objects;
 
@@ -28,10 +28,10 @@
      * The nodes to transform.
      */
-    protected Collection<Node> nodes = new LinkedList<>();
+    protected final Collection<Node> nodes;
 
     /**
      * List of all old states of the nodes.
      */
-    protected Map<Node, OldNodeState> oldStates = new HashMap<>();
+    protected final Map<Node, OldNodeState> oldStates = new HashMap<>();
 
     /**
@@ -47,7 +47,10 @@
      * Creates a TransformNodesObject.
      * Find out the impacted nodes and store their initial state.
-     * @param objects objects to fetch nodes from
+     * @param objects objects to fetch nodes from. Must neither be null nor empty. Items must belong to a data set
+     * @throws NullPointerException if objects is null or contain null item
+     * @throws NoSuchElementException if objects is empty
      */
     public TransformNodesCommand(Collection<? extends OsmPrimitive> objects) {
+        super(objects.iterator().next().getDataSet());
         this.nodes = AllNodesVisitor.getAllNodes(objects);
         storeOldState();
Index: trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java	(revision 12726)
@@ -79,5 +79,5 @@
     public void undoCommand() {
         DataSet ds = getAffectedDataSet();
-        if (!Main.main.containsDataSet(ds)) {
+        if (Main.main != null && !Main.main.containsDataSet(ds)) {
             Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
                     ds.getName(),
Index: trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java	(revision 12726)
@@ -28,7 +28,9 @@
     /**
      * Constructs a new {@code ConflictResolveCommand} in the context of the current edit layer, if any.
+     * @deprecated to be removed end of 2017. Use {@link #ConflictResolveCommand(DataSet)} instead
      */
+    @Deprecated
     public ConflictResolveCommand() {
-        // Do nothing
+        this(Main.main.getEditDataSet());
     }
 
@@ -81,13 +83,15 @@
 
         DataSet ds = getAffectedDataSet();
-        if (!Main.main.containsDataSet(ds)) {
-            Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
-                    this.toString(),
-                    ds.getName()
-            ));
-            return;
+        if (Main.main != null) {
+            if (!Main.main.containsDataSet(ds)) {
+                Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
+                        this.toString(),
+                        ds.getName()
+                ));
+                return;
+            }
+
+            Main.main.setEditDataSet(ds);
         }
-
-        Main.main.setEditDataSet(ds);
         reconstituteConflicts();
     }
Index: trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/CoordinateConflictResolveCommand.java	(revision 12726)
@@ -34,4 +34,5 @@
      */
     public CoordinateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
         this.decision = decision;
Index: trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/DeletedStateConflictResolveCommand.java	(revision 12726)
@@ -34,4 +34,5 @@
      */
     public DeletedStateConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, MergeDecisionType decision) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
         this.decision = decision;
Index: trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java	(revision 12726)
@@ -29,4 +29,5 @@
      */
     public ModifiedConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
     }
Index: trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java	(revision 12726)
@@ -36,4 +36,5 @@
     @SuppressWarnings("unchecked")
     public RelationMemberConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<RelationMember> mergedMembers) {
+        super(conflict.getMy().getDataSet());
         this.conflict = (Conflict<Relation>) conflict;
         this.mergedMembers = mergedMembers;
Index: trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/TagConflictResolveCommand.java	(revision 12726)
@@ -50,4 +50,5 @@
      */
     public TagConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict, List<TagMergeItem> mergeItems) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
         this.mergeItems = mergeItems;
Index: trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java	(revision 12726)
@@ -29,4 +29,5 @@
      */
     public VersionConflictResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
+        super(conflict.getMy().getDataSet());
         this.conflict = conflict;
     }
Index: trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java
===================================================================
--- trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java	(revision 12726)
@@ -36,4 +36,5 @@
     @SuppressWarnings("unchecked")
     public WayNodesConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<Node> mergedNodeList) {
+        super(conflict.getMy().getDataSet());
         this.conflict = (Conflict<Way>) conflict;
         this.mergedNodeList = mergedNodeList;
Index: trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/data/osm/DataSet.java	(revision 12726)
@@ -263,4 +263,21 @@
 
     /**
+     * Constructs a new {@code DataSet} initially filled with the given primitives.
+     * @param osmPrimitives primitives to add to this data set
+     * @since 12726
+     */
+    public DataSet(OsmPrimitive... osmPrimitives) {
+        this();
+        beginUpdate();
+        try {
+            for (OsmPrimitive o : osmPrimitives) {
+                addPrimitive(o);
+            }
+        } finally {
+            endUpdate();
+        }
+    }
+
+    /**
      * Adds a new data source.
      * @param source data source to add
Index: trunk/src/org/openstreetmap/josm/data/osm/Node.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/data/osm/Node.java	(revision 12726)
@@ -106,4 +106,5 @@
      * @return the east north coordinates or {@code null} if #is
      */
+    @Override
     public EastNorth getEastNorth() {
         return getEastNorth(Main.getProjection());
Index: trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java	(revision 12726)
@@ -168,5 +168,5 @@
         mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
         minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0);
-        DataSet dataSet = Main.main.getEditDataSet();
+        DataSet dataSet = Main.main != null ? Main.main.getEditDataSet() : null;
         dsArea = dataSet == null ? null : dataSet.getDataSourceArea();
     }
Index: trunk/src/org/openstreetmap/josm/gui/MainApplication.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/gui/MainApplication.java	(revision 12726)
@@ -197,4 +197,24 @@
     public static UndoRedoHandler undoRedo;
 
+    private static final LayerChangeListener undoRedoCleaner = new LayerChangeListener() {
+        @Override
+        public void layerRemoving(LayerRemoveEvent e) {
+            Layer layer = e.getRemovedLayer();
+            if (layer instanceof OsmDataLayer) {
+                undoRedo.clean(((OsmDataLayer) layer).data);
+            }
+        }
+
+        @Override
+        public void layerOrderChanged(LayerOrderChangeEvent e) {
+            // Do nothing
+        }
+
+        @Override
+        public void layerAdded(LayerAddEvent e) {
+            // Do nothing
+        }
+    };
+
     /**
      * Listener that sets the enabled state of undo/redo menu entries.
@@ -220,23 +240,5 @@
         this.mainFrame = mainFrame;
         undoRedo = super.undoRedo;
-        getLayerManager().addLayerChangeListener(new LayerChangeListener() {
-            @Override
-            public void layerRemoving(LayerRemoveEvent e) {
-                Layer layer = e.getRemovedLayer();
-                if (layer instanceof OsmDataLayer) {
-                    undoRedo.clean(((OsmDataLayer) layer).data);
-                }
-            }
-
-            @Override
-            public void layerOrderChanged(LayerOrderChangeEvent e) {
-                // Do nothing
-            }
-
-            @Override
-            public void layerAdded(LayerAddEvent e) {
-                // Do nothing
-            }
-        });
+        getLayerManager().addLayerChangeListener(undoRedoCleaner);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java	(revision 12726)
@@ -77,7 +77,7 @@
 import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
+import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
 import org.openstreetmap.josm.data.osm.search.SearchCompiler;
 import org.openstreetmap.josm.data.osm.search.SearchSetting;
-import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
 import org.openstreetmap.josm.data.preferences.StringProperty;
 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
Index: trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java	(revision 12726)
@@ -103,9 +103,10 @@
      */
     protected void applyExistingNonConflictingRelation(TagEditorModel tagEditorModel) {
-        Relation editedRelation = new Relation(editor.getRelation());
+        Relation originRelation = editor.getRelation();
+        Relation editedRelation = new Relation(originRelation);
         tagEditorModel.applyToPrimitive(editedRelation);
         memberTableModel.applyToRelation(editedRelation);
-        if (!editedRelation.hasEqualSemanticAttributes(editor.getRelation(), false)) {
-            MainApplication.undoRedo.add(new ChangeCommand(editor.getRelation(), editedRelation));
+        if (!editedRelation.hasEqualSemanticAttributes(originRelation, false)) {
+            MainApplication.undoRedo.add(new ChangeCommand(originRelation, editedRelation));
         }
     }
Index: trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/gui/io/TagSettingsPanel.java	(revision 12726)
@@ -158,5 +158,5 @@
     class ChangesetReviewChangeListener implements ChangeListener {
 
-        private final String key = "review_requested";
+        private static final String KEY = "review_requested";
 
         @Override
@@ -164,7 +164,7 @@
             if (e.getSource() instanceof ChangesetReviewModel) {
                 boolean newState = ((ChangesetReviewModel) e.getSource()).isReviewRequested();
-                boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(key)).orElse(""));
+                boolean oldState = "yes".equals(Optional.ofNullable(getTagEditorValue(KEY)).orElse(""));
                 if (oldState != newState) {
-                    setProperty(key, newState ? "yes" : null);
+                    setProperty(KEY, newState ? "yes" : null);
                 }
             }
Index: trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java	(revision 12726)
@@ -12,4 +12,5 @@
 import org.openstreetmap.josm.command.AddCommand;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -96,11 +97,12 @@
         }
 
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
         if (node == null) {
             node = new Node(ll);
             // Now execute the commands to add this node.
-            MainApplication.undoRedo.add(new AddCommand(node));
+            MainApplication.undoRedo.add(new AddCommand(ds, node));
         }
 
-        MainApplication.getLayerManager().getEditDataSet().setSelected(node);
+        ds.setSelected(node);
         if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
             AutoScaleAction.autoScale("selection");
Index: trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java	(revision 12726)
@@ -19,4 +19,5 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.data.coor.LatLon;
+import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
@@ -148,5 +149,5 @@
             nd = new Node(ll);
             // Now execute the commands to add this node.
-            commands.add(new AddCommand(nd));
+            commands.add(new AddCommand(Main.main.getEditDataSet(), nd));
             addedNodes.put(ll, nd);
         }
@@ -166,7 +167,8 @@
         }
         allCoordinates.clear();
-        commands.add(new AddCommand(way));
+        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
+        commands.add(new AddCommand(ds, way));
         MainApplication.undoRedo.add(new SequenceCommand(tr("Add way"), commands));
-        MainApplication.getLayerManager().getEditDataSet().setSelected(way);
+        ds.setSelected(way);
         if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
             AutoScaleAction.autoScale("selection");
Index: trunk/src/org/openstreetmap/josm/tools/Geometry.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 12725)
+++ trunk/src/org/openstreetmap/josm/tools/Geometry.java	(revision 12726)
@@ -228,5 +228,5 @@
             newWay.setNodes(newNodes[pos]);
 
-            cmds.add(new ChangeCommand(way, newWay));
+            cmds.add(new ChangeCommand(dataset, way, newWay));
         }
 
