Index: /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java
===================================================================
--- /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java	(revision 21473)
+++ /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxLayer.java	(revision 21474)
@@ -38,5 +38,5 @@
 
 	private static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(EditGpxPlugin.class.getResource("/images/editgpx_layer.png")));
-	private final EditGpxData data;
+	public final EditGpxData data;
 	private GPXLayerImportAction layerImport;
 
Index: /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java
===================================================================
--- /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java	(revision 21473)
+++ /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxMode.java	(revision 21474)
@@ -3,4 +3,6 @@
  */
 package org.openstreetmap.josm.plugins.editgpx;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
 
 import java.awt.Color;
@@ -11,8 +13,12 @@
 import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
+import java.util.List;
 
 import org.openstreetmap.josm.Main;
 import org.openstreetmap.josm.actions.mapmode.MapMode;
 import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.MapView;
+import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
+import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.plugins.editgpx.data.EditGpxData;
 import org.openstreetmap.josm.plugins.editgpx.data.EditGpxTrack;
@@ -21,16 +27,15 @@
 
 
-public class EditGpxMode extends MapMode {
+public class EditGpxMode extends MapMode implements LayerChangeListener {
 
 	private static final long serialVersionUID = 7940589057093872411L;
 	Point pointPressed;
-	EditGpxData data;
 	MapFrame mapFrame;
 	Rectangle oldRect;
 	MapFrame frame;
+	EditGpxLayer currentEditLayer;
 
-	public EditGpxMode(MapFrame mapFrame, String name, String desc, EditGpxData gpxData) {
+	public EditGpxMode(MapFrame mapFrame, String name, String desc) {
 		super(name, "editgpx_mode.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
-		this.data = gpxData;
 	}
 
@@ -39,4 +44,6 @@
 		Main.map.mapView.addMouseListener(this);
 		Main.map.mapView.addMouseMotionListener(this);
+		MapView.addLayerChangeListener(this);
+		updateLayer();
 	}
 
@@ -63,11 +70,13 @@
 		if (e.getButton() != MouseEvent.BUTTON1) {
 			return;
-		} else {
-			Point pointReleased = e.getPoint();
+		}
 
-			Rectangle r = createRect(pointReleased, pointPressed);
+		Point pointReleased = e.getPoint();
 
-			//go through nodes and mark the ones in the selection rect as deleted
-			for (EditGpxTrack track: data.getTracks()) {
+		Rectangle r = createRect(pointReleased, pointPressed);
+
+		//go through nodes and mark the ones in the selection rect as deleted
+		if (currentEditLayer != null) {
+			for (EditGpxTrack track: currentEditLayer.data.getTracks()) {
 				for (EditGpxTrackSegment segment: track.getSegments()) {
 					for (EditGpxWayPoint wayPoint: segment.getWayPoints()) {
@@ -79,7 +88,8 @@
 				}
 			}
-			oldRect = null;
-			Main.map.mapView.repaint();
 		}
+		oldRect = null;
+		Main.map.mapView.repaint();
+
 	}
 
@@ -139,3 +149,30 @@
 		frame = mapFrame;
 	}
+
+	/**
+	 * create new layer, add listeners and try importing gpx data.
+	 */
+	private void updateLayer() {
+
+		List<EditGpxLayer> layers = Main.map.mapView.getLayersOfType(EditGpxLayer.class);
+		currentEditLayer = layers.isEmpty()?null:layers.get(0);
+
+		if(currentEditLayer == null) {
+			currentEditLayer = new EditGpxLayer(tr("EditGpx"), new EditGpxData());
+			Main.main.addLayer(currentEditLayer);
+			currentEditLayer.initializeImport();
+		}
+		Main.map.mapView.repaint();
+	}
+
+	public void activeLayerChange(Layer oldLayer, Layer newLayer) { }
+
+	public void layerAdded(Layer newLayer) { }
+
+	public void layerRemoved(Layer oldLayer) {
+		if (oldLayer instanceof EditGpxLayer) {
+			currentEditLayer = null;
+		}
+	}
+
 }
Index: /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java
===================================================================
--- /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java	(revision 21473)
+++ /applications/editors/josm/plugins/editgpx/src/org/openstreetmap/josm/plugins/editgpx/EditGpxPlugin.java	(revision 21474)
@@ -6,6 +6,4 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.net.URL;
 
@@ -15,10 +13,6 @@
 import org.openstreetmap.josm.gui.IconToggleButton;
 import org.openstreetmap.josm.gui.MapFrame;
-import org.openstreetmap.josm.gui.MapView;
-import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
-import org.openstreetmap.josm.gui.layer.Layer;
 import org.openstreetmap.josm.plugins.Plugin;
 import org.openstreetmap.josm.plugins.PluginInformation;
-import org.openstreetmap.josm.plugins.editgpx.data.EditGpxData;
 
 /**
@@ -40,12 +34,8 @@
 	private IconToggleButton btn;
 	private EditGpxMode mode;
-	protected static EditGpxLayer eGpxLayer;
-	protected static EditGpxData gpxData;
-	public static boolean active = false;
 
 	public EditGpxPlugin(PluginInformation info) {
 		super(info);
-		gpxData = new EditGpxData();
-		mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks"), gpxData);
+		mode = new EditGpxMode(Main.map, "editgpx", tr("edit gpx tracks"));
 
 		btn = new IconToggleButton(mode);
@@ -63,51 +53,5 @@
 			if(Main.map != null)
 				Main.map.addMapMode(btn);
-
-			active = btn.isSelected();
-
-			btn.addActionListener(new ActionListener() {
-				public void actionPerformed(ActionEvent e) {
-					active = btn.isSelected();
-					if (active) {
-						Main.worker.execute(new Runnable() {
-							public void run() {
-								updateLayer();
-							}
-						});
-					}
-				}
-			});
 		}
-	}
-
-	/**
-	 * create new layer, add listeners and try importing gpx data.
-	 */
-	private void updateLayer() {
-		if(eGpxLayer == null) {
-			eGpxLayer = new EditGpxLayer(tr("EditGpx"), gpxData);
-			Main.main.addLayer(eGpxLayer);
-			MapView.addLayerChangeListener(new LayerChangeListener(){
-
-				public void activeLayerChange(final Layer oldLayer, final Layer newLayer) {
-					if(newLayer instanceof EditGpxLayer)
-						EditGpxPlugin.eGpxLayer = (EditGpxLayer)newLayer;
-				}
-
-				public void layerAdded(final Layer newLayer) {
-				}
-
-				public void layerRemoved(final Layer oldLayer) {
-					if(oldLayer == eGpxLayer) {
-						eGpxLayer = null;
-						//dataSet = new DataSet();
-						MapView.removeLayerChangeListener(this);
-					}
-				}
-			});
-
-			eGpxLayer.initializeImport();
-		}
-		Main.map.mapView.repaint();
 	}
 
