Index: plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAlgnSegment.java
===================================================================
--- plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAlgnSegment.java	(revision 33135)
+++ plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysAlgnSegment.java	(working copy)
@@ -5,6 +5,7 @@
 import java.awt.Graphics2D;
 import java.awt.Point;
 import java.awt.Shape;
+import java.awt.RenderingHints;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.Line2D;
 import java.util.ArrayList;
@@ -37,7 +38,7 @@
 
     private enum PivotLocations {
         NONE, NODE1, NODE2, CENTRE
-    };
+    }
 
     private PivotLocations currPivot;
     Map<PivotLocations, EastNorth> pivotList = new EnumMap<>(
@@ -118,9 +119,9 @@
             EastNorth n2;
             switch (pp) {
             case NODE1:
-                return segment.way.getNode(segment.lowerIndex).getEastNorth();
+                return segment.getFirstNode().getEastNorth();
             case NODE2:
-                return segment.way.getNode(segment.lowerIndex + 1).getEastNorth();
+                return segment.getSecondNode().getEastNorth();
             case CENTRE:
                 n1 = getPivotCoord(PivotLocations.NODE1);
                 n2 = getPivotCoord(PivotLocations.NODE2);
@@ -226,9 +227,15 @@
 
     @Override
     public void paint(Graphics2D g, MapView mv, Bounds bbox) {
-        // Note: segment should never be null here
         super.paint(g, mv, bbox);
 
+        // Note: segment should never be null here, and its nodes should never be missing.
+        // If they are, it's a bug, possibly related to tracking of DataSet deletions.
+        if (segment.way.getNodesCount() <= segment.lowerIndex + 1) {
+            Main.warn("Not drawing AlignWays pivot points: underlying nodes disappeared");
+            return;
+        }
+
         // Ensure consistency
         updatePivotsEndpoints();
 
@@ -246,6 +253,7 @@
     private void highlightPivot(Graphics2D g, MapView mv, EastNorth pivot) {
         g.setColor(pivotColor);
         g.setStroke(new BasicStroke());
+        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 
         Shape pvCentrePoint = new Ellipse2D.Double(
                 mv.getPoint(pivot).getX() - 5.0f,
@@ -271,6 +279,8 @@
 
         g.setColor(crossColor);
         g.setStroke(new BasicStroke());
+        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
         g.draw(crossV);
         g.draw(crossH);
 
Index: plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepLength.java
===================================================================
--- plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepLength.java	(revision 33135)
+++ plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysCmdKeepLength.java	(working copy)
@@ -9,6 +9,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Collections;
 
 import javax.swing.Icon;
 import javax.swing.JOptionPane;
@@ -91,15 +92,11 @@
         this.pivot = algnSeg.getCurrPivotCoord();
         this.displaceableNodes = algnSeg.getSegmentEndPoints();
 
-        EastNorth enRefNode1 = refWS.way.getNode(refWS.lowerIndex)
-                .getEastNorth();
-        EastNorth enRefNode2 = refWS.way.getNode(refWS.lowerIndex + 1)
-                .getEastNorth();
+        EastNorth enRefNode1 = refWS.getFirstNode().getEastNorth();
+        EastNorth enRefNode2 = refWS.getSecondNode().getEastNorth();
 
-        EastNorth enAlgnNode1 = algnWS.way.getNode(algnWS.lowerIndex)
-                .getEastNorth();
-        EastNorth enAlgnNode2 = algnWS.way.getNode(algnWS.lowerIndex + 1)
-                .getEastNorth();
+        EastNorth enAlgnNode1 = algnWS.getFirstNode().getEastNorth();
+        EastNorth enAlgnNode2 = algnWS.getSecondNode().getEastNorth();
 
         // Calculate the rotation angle
         double refAngle = Math.atan2(enRefNode1.north() - enRefNode2.north(),
@@ -205,6 +202,13 @@
     }
 
     @Override
+    public Collection<? extends OsmPrimitive> getParticipatingPrimitives() {
+        Collection<OsmPrimitive> prims = new HashSet<>(displaceableNodes);
+        prims.add(algnSeg.getSegment().way);
+        return Collections.unmodifiableCollection(prims);
+    }
+
+    @Override
     public boolean executeCommand() {
         rotateNodes(true);
         return true;
Index: plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysDialog.java
===================================================================
--- plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysDialog.java	(revision 33135)
+++ plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysDialog.java	(working copy)
@@ -10,6 +10,7 @@
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.util.Objects;
 
 import javax.swing.BorderFactory;
 import javax.swing.Box;
@@ -116,10 +117,10 @@
 
     @Override
     public void actionPerformed(ActionEvent e) {
-        if (e.getActionCommand() == "awOptKeepLen") {
+        if (Objects.equals(e.getActionCommand(), "awOptKeepLen")) {
             awOpt = AligningModeOption.ALGN_OPT_KEEP_LENGTH;
             infoText.setText(tr("<html>Aligns the way segment to the reference so that its length is preserved.</html>"));
-        } else if (e.getActionCommand() == "awOptKeepAng") {
+        } else if (Objects.equals(e.getActionCommand(), "awOptKeepAng")) {
             awOpt = AligningModeOption.ALGN_OPT_KEEP_ANGLE;
             infoText.setText(tr("<html>Aligns the way segment to the reference so that the angles of its adjacent segments are preserved.<br/>" +
                     "The length of the aligned segment is likely to change as result.</html>"));
@@ -135,7 +136,7 @@
 
 
     /**
-     * @param action If set to true, the dialog will show the mode options, otherwise it will show some instructions
+     * @param activeMode If set to true, the dialog will show the mode options, otherwise it will show some instructions
      */
     public void activate(boolean activeMode) {
 
Index: plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysMode.java
===================================================================
--- plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysMode.java	(revision 33135)
+++ plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysMode.java	(working copy)
@@ -20,9 +20,11 @@
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.event.*;
 import org.openstreetmap.josm.gui.IconToggleButton;
 import org.openstreetmap.josm.gui.MapFrame;
 import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.OsmDataLayer;
 import org.openstreetmap.josm.tools.Shortcut;
 
 /**
@@ -30,7 +32,7 @@
  * Handles the state machine and user interaction (mouse clicks).
  *
  */
-public class AlignWaysMode extends MapMode /* implements MapViewPaintable */{
+public class AlignWaysMode extends MapMode implements DataSetListener {
 
     private static final long serialVersionUID = -1090955708412011141L;
     private final AlignWaysState noneSelected;
@@ -77,6 +79,9 @@
 
         awSegs = AlignWaysSegmentMgr.getInstance(Main.map.mapView);
         Main.map.mapView.addMouseListener(this);
+        DataSet ds = Main.getLayerManager().getEditDataSet();
+        if (ds != null)
+            ds.addDataSetListener(this);
         setCurrentState(noneSelected);
     }
 
@@ -94,6 +99,9 @@
 
         setCurrentState(noneSelected);
         Main.map.mapView.removeMouseListener(this);
+        DataSet ds = Main.getLayerManager().getEditDataSet();
+        if (ds != null)
+            ds.removeDataSetListener(this);
         AlignWaysPlugin.getAwAction().setEnabled(false);
     }
 
@@ -127,26 +135,43 @@
             }
         }
 
-        // Activate the Align Ways button if we have enough selections
-        if (currentState == bothSelected) {
-            AlignWaysPlugin.getAwAction().setEnabled(true);
-        } else {
-            AlignWaysPlugin.getAwAction().setEnabled(false);
-        }
         Main.map.mapView.repaint();
     }
 
     /**
-     * @param currentState
-     *            One of the AlignWays states
+     * Sets the current state based on the selected segments.
+     * @param mgr AlignWays segment manager singleton
      */
+    public void setCurrentState(AlignWaysSegmentMgr mgr) {
+
+        boolean algnSelected = mgr.getAlgnSeg() != null;
+        boolean refSelected = mgr.getRefSeg() != null;
+
+        if (algnSelected && refSelected)
+            setCurrentState(getBothSelected());
+        else if (algnSelected)
+            setCurrentState(getAligneeSelected());
+        else if (refSelected)
+            setCurrentState(getReferenceSelected());
+        else
+            setCurrentState(getNoneSelected());
+    }
+
+    /**
+     * Sets the current state.
+     * @param currentState One of the AlignWays states
+     */
     public void setCurrentState(AlignWaysState currentState) {
         this.currentState = currentState;
         currentState.setHelpText();
 
+        // Activate the Align Ways button if we have enough selections
+        AlignWaysPlugin.getAwAction().setEnabled(currentState == bothSelected);
+
         if (currentState == noneSelected) {
             awSegs.cleanupWays();
-            // TODO getCurrentDataSet may return null when the editable layer had
+
+            // getEditDataSet() may return null when the editable layer had
             // already been removed by JOSM. This happens e.g. when the user closes
             // JOSM while AlignWays mode is still active.
             DataSet ds = getLayerManager().getEditDataSet();
@@ -184,13 +209,6 @@
         return bothSelected;
     }
 
-    /**
-     * @return the current state
-     */
-    public AlignWaysState getCurrentState() {
-        return currentState;
-    }
-
     private void showTips() {
 
         AlignWaysTipsPanel atp = new AlignWaysTipsPanel();
@@ -228,9 +246,54 @@
 
     @Override
     public boolean layerIsSupported(Layer l) {
-        if (l == null)
-            return false;
-        else
-            return true;
+        return l instanceof OsmDataLayer;
     }
+
+    @Override
+    protected void updateEnabledState() {
+        setEnabled(getLayerManager().getEditLayer() != null);
+    }
+
+    /* --------------- *
+     * DataSetListener *
+     * --------------- */
+
+    @Override
+    public void primitivesAdded(PrimitivesAddedEvent event) {
+    }
+
+    @Override
+    public void primitivesRemoved(PrimitivesRemovedEvent event) {
+        awSegs = AlignWaysSegmentMgr.getInstance(Main.map.mapView);
+
+        // Check whether any of the removed primitives were part of a highlighted alignee or reference segment.
+        // If so: remove the affected segment and update the state accordingly.
+        if (awSegs.primitivesRemoved(event.getPrimitives()))
+            setCurrentState(awSegs);
+    }
+
+    @Override
+    public void tagsChanged(TagsChangedEvent event) {
+    }
+
+    @Override
+    public void nodeMoved(NodeMovedEvent event) {
+    }
+
+    @Override
+    public void wayNodesChanged(WayNodesChangedEvent event) {
+    }
+
+    @Override
+    public void relationMembersChanged(RelationMembersChangedEvent event) {
+    }
+
+    @Override
+    public void otherDatasetChange(AbstractDatasetChangedEvent event) {
+    }
+
+    @Override
+    public void dataChanged(DataChangedEvent event) {
+    }
+
 }
Index: plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegment.java
===================================================================
--- plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegment.java	(revision 33135)
+++ plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegment.java	(working copy)
@@ -9,6 +9,7 @@
 import java.awt.Color;
 import java.awt.Graphics2D;
 import java.awt.Point;
+import java.awt.RenderingHints;
 import java.awt.geom.Line2D;
 import java.util.Collection;
 import java.util.HashSet;
@@ -18,6 +19,7 @@
 import org.openstreetmap.josm.data.Bounds;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
+import org.openstreetmap.josm.data.osm.Way;
 import org.openstreetmap.josm.data.osm.WaySegment;
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.layer.MapViewPaintable;
@@ -56,12 +58,9 @@
     void setSegmentEndpoints(WaySegment segment) {
         if (segment != null) {
             try {
-                Node node1 = segment.way.getNode(segment.lowerIndex);
-                Node node2 = segment.way.getNode(segment.lowerIndex + 1);
-
                 segmentEndPoints = new HashSet<>();
-                segmentEndPoints.add(node1);
-                segmentEndPoints.add(node2);
+                segmentEndPoints.add(segment.getFirstNode());
+                segmentEndPoints.add(segment.getSecondNode());
             } catch (IndexOutOfBoundsException e) {
                 Main.error(e);
             }
@@ -88,23 +87,27 @@
 
     @Override
     public void paint(Graphics2D g, MapView mv, Bounds bbox) {
+        // Note: segment should never be null here, and its nodes should never be missing.
+        // If they are, it's a bug, possibly related to tracking of DataSet deletions.
+        if (segment.way.getNodesCount() <= segment.lowerIndex + 1) {
+            Main.warn("Not drawing AlignWays highlighting segment: underlying nodes disappeared");
+            return;
+        }
+
         highlightSegment(segmentColor, g, mv);
     }
 
     protected void highlightSegment(Color c, Graphics2D g, MapView mv) {
-        if (segment.way.getNodesCount() == 0) {
-            return;
-        }
-
         g.setColor(c);
         g.setStroke(new BasicStroke(6, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
         drawSegment(g, mv);
     }
 
     protected void drawSegment(Graphics2D g, MapView mv) {
         try {
-            Node n1 = segment.way.getNode(segment.lowerIndex);
-            Node n2 = segment.way.getNode(segment.lowerIndex + 1);
+            Node n1 = segment.getFirstNode();
+            Node n2 = segment.getSecondNode();
 
             g.draw(new Line2D.Double(mv.getPoint(n1), mv.getPoint(n2)));
         } catch (IndexOutOfBoundsException e) {
@@ -112,6 +115,15 @@
         }
     }
 
+    protected boolean containsPrimitive(OsmPrimitive primitive) {
+        if (segment == null)
+            return false;
+
+        return (primitive instanceof Way && segment.way.equals(primitive)) ||
+                (primitive instanceof Node && segmentEndPoints.contains(primitive));
+
+    }
+
      @Override
      public int hashCode() {
         if (segment == null) {
Index: plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegmentMgr.java
===================================================================
--- plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegmentMgr.java	(revision 33135)
+++ plugins/alignways/src/com/tilusnet/josm/plugins/alignways/AlignWaysSegmentMgr.java	(working copy)
@@ -4,11 +4,13 @@
 
 import java.awt.Point;
 import java.util.Collection;
+import java.util.List;
 
 import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.data.osm.Node;
+import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.gui.MapView;
 
 /**
@@ -30,12 +32,13 @@
         mv = mapView;
     }
 
+    /**
+     * Get or creates the segment manager instance belonging to a given MapView.
+     */
     public static AlignWaysSegmentMgr getInstance(MapView mapView) {
-        if (singleton == null) {
-            synchronized (AlignWaysSegmentMgr.class) {
-                if (singleton == null) {
-                    singleton = new AlignWaysSegmentMgr(mapView);
-                }
+        synchronized (AlignWaysSegmentMgr.class) {
+            if (singleton == null || !singleton.getMapView().equals(mapView)) {
+                singleton = new AlignWaysSegmentMgr(mapView);
             }
         }
         return singleton;
@@ -42,6 +45,13 @@
     }
 
     /**
+     * @return The MapView this segment manager belongs to.
+     */
+    private MapView getMapView() {
+        return mv;
+    }
+
+    /**
      * @param clickedPoint
      *            Point nearby where user probably clicked
      * @return true, if alignee changed, false otherwise
@@ -48,42 +58,38 @@
      */
     public boolean algnUpdate(Point clickedPoint) {
 
-        if (algnSeg != null) {
-            // Check first if there is a pivot point nearby that needs selection
-            if (algnSeg.updatePivot(clickedPoint))
-                // Updated pivot, alignee reference unchanged
-                return false;
+        // Check first if there is a pivot point nearby that needs selection
+        if (algnSeg != null && algnSeg.updatePivot(clickedPoint)) {
+            // Updated pivot, alignee reference unchanged
+            return false;
         }
 
         // Previous attempt of pivot update unsuccessful, check alignee update
-        AlignWaysAlgnSegment tmpAlgnSeg = new AlignWaysAlgnSegment(mv,
-                clickedPoint);
+        AlignWaysAlgnSegment tmpAlgnSeg = new AlignWaysAlgnSegment(mv, clickedPoint);
         if (tmpAlgnSeg.getSegment() == null)
             return false;
-        else {
-            // Found a segment
-            // It may happen that the new segment is identical with the already
-            // selected reference:
-            if ((refSeg != null) && (tmpAlgnSeg.equals(refSeg))) {
-                // This action is then ignored (we won't clear the reference
-                // segment)
-                JOptionPane.showMessageDialog(Main.parent,
-                        tr("Segment to be aligned cannot be the same with the reference segment.\n" +
-                        "Please choose a different segment to be aligned."),
-                        tr("AlignWayS message"), JOptionPane.WARNING_MESSAGE);
-                return false;
-            }
-            // This will be a new alignee, old alignee (if any) will be lost:
-            if (algnSeg != null) {
-                algnSeg.destroy();
-            }
 
-            // Update alignee
-            algnSeg = tmpAlgnSeg;
+        // Found a segment - it may happen that the new segment is identical with the already
+        // selected asignee or reference segment. This action is then ignored.
+        if (algnSeg != null && tmpAlgnSeg.equals(algnSeg)) {
+            return false;
+        }
+        else if (refSeg != null && tmpAlgnSeg.equals(refSeg)) {
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("Segment to be aligned cannot be the same with the reference segment.\n" +
+                    "Please choose a different segment to be aligned."),
+                    tr("AlignWayS message"), JOptionPane.WARNING_MESSAGE);
+            return false;
+        }
 
-            return true;
+        // This will be a new alignee, old alignee (if any) will be lost:
+        if (algnSeg != null) {
+            algnSeg.destroy();
         }
 
+        // Update alignee
+        algnSeg = tmpAlgnSeg;
+        return true;
     }
 
     /**
@@ -93,35 +99,31 @@
      */
     public boolean refUpdate(Point clickedPoint) {
 
-        AlignWaysRefSegment tmpRefSeg = new AlignWaysRefSegment(mv,
-                clickedPoint);
-        // TODO Have to check what happens when refSeg wasn't null previously
+        AlignWaysRefSegment tmpRefSeg = new AlignWaysRefSegment(mv, clickedPoint);
         if (tmpRefSeg.getSegment() == null)
             return false;
-        else {
-            // Found a segment
-            // It may happen that the new segment is identical with the already
-            // selected alignee:
-            if ((algnSeg != null) && (tmpRefSeg.equals(algnSeg))) {
-                // This action is then ignored (we won't clear the alignee
-                // segment)
-                JOptionPane.showMessageDialog(Main.parent,
-                        tr("Reference segment cannot be the same with the segment to be aligned.\n" +
-                        "Please choose a different reference segment."),
-                        tr("AlignWayS message"), JOptionPane.WARNING_MESSAGE);
-                return false;
-            }
-            // This will be a new reference, old reference (if any) will be lost:
-            if (refSeg != null) {
-                refSeg.destroy();
-            }
 
-            // Update reference
-            refSeg = tmpRefSeg;
-            return true;
+        // Found a segment - it may happen that the new segment is identical with the already
+        // selected asignee or reference segment. This action is then ignored.
+        if (refSeg != null && refSeg.equals(tmpRefSeg)) {
+            return false;
+        }
+        else if (algnSeg != null && tmpRefSeg.equals(algnSeg)) {
+            JOptionPane.showMessageDialog(Main.parent,
+                    tr("Reference segment cannot be the same with the segment to be aligned.\n" +
+                    "Please choose a different reference segment."),
+                    tr("AlignWayS message"), JOptionPane.WARNING_MESSAGE);
+            return false;
+        }
 
+        // This will be a new reference, old reference (if any) will be lost:
+        if (refSeg != null) {
+            refSeg.destroy();
         }
 
+        // Update reference
+        refSeg = tmpRefSeg;
+        return true;
     }
 
     /**
@@ -158,4 +160,27 @@
         return refSeg;
     }
 
+
+    /**
+     * Handles the event that OSM primitives were removed and checks whether
+     * this invalidates the currently selected alignee or reference segment.
+     * @return Whether any of the selected segments were invalidated.
+     * @param primitives List of primitives that were removed.
+     */
+    public boolean primitivesRemoved(List<? extends OsmPrimitive> primitives) {
+        boolean changed = false;
+        for (OsmPrimitive p : primitives) {
+            if (algnSeg != null && algnSeg.containsPrimitive(p)) {
+                algnSeg.destroy();
+                algnSeg = null;
+                changed = true;
+            }
+            if (refSeg != null && refSeg.containsPrimitive(p)) {
+                refSeg.destroy();
+                refSeg = null;
+                changed = true;
+            }
+        }
+        return changed;
+    }
 }
