Index: applications/editors/josm/plugins/livegps/build.xml
===================================================================
--- applications/editors/josm/plugins/livegps/build.xml	(revision 16942)
+++ applications/editors/josm/plugins/livegps/build.xml	(revision 16945)
@@ -26,5 +26,5 @@
                 <attribute name="Plugin-Description" value="Support live GPS input (moving dot) through a connection to gpsd server."/>
                 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/LiveGPS"/>
-                <attribute name="Plugin-Mainversion" value="1725"/>
+                <attribute name="Plugin-Mainversion" value="1890"/>
                 <attribute name="Plugin-Stage" value="50"/>
                 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/>
Index: applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
===================================================================
--- applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java	(revision 16942)
+++ applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java	(revision 16945)
@@ -36,4 +36,14 @@
         if(!propertyChangeListener.contains(listener)) {
             propertyChangeListener.add(listener);
+        }
+    }
+
+    /**
+     * Remove a property change listener from the acquirer.
+     * @param listener the new listener
+     */
+    public void removePropertyChangeListener(PropertyChangeListener listener) {
+        if(propertyChangeListener.contains(listener)) {
+            propertyChangeListener.remove(listener);
         }
     }
Index: applications/editors/josm/plugins/livegps/src/livegps/LiveGpsData.java
===================================================================
--- applications/editors/josm/plugins/livegps/src/livegps/LiveGpsData.java	(revision 16942)
+++ applications/editors/josm/plugins/livegps/src/livegps/LiveGpsData.java	(revision 16945)
@@ -163,5 +163,5 @@
      */
     public Way getWay() {
-        if(way == null) {
+        if(way == null && Main.map != null && Main.map.mapView != null) {
             Point xy = Main.map.mapView.getPoint(getLatLon());
             way = Main.map.mapView.getNearestWay(xy);
Index: applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
===================================================================
--- applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java	(revision 16942)
+++ applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java	(revision 16945)
@@ -138,5 +138,5 @@
      */
     public void propertyChange(PropertyChangeEvent evt) {
-        if(!visible) {
+        if(!isVisible()) {
             return;
         }
@@ -154,6 +154,4 @@
             }
         }
-
     }
-
 }
Index: applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java
===================================================================
--- applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java	(revision 16942)
+++ applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java	(revision 16945)
@@ -19,8 +19,10 @@
 import org.openstreetmap.josm.gui.MainMenu;
 import org.openstreetmap.josm.gui.MapFrame;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener;
 import org.openstreetmap.josm.plugins.Plugin;
 import org.openstreetmap.josm.tools.Shortcut;
 
-public class LiveGpsPlugin extends Plugin
+public class LiveGpsPlugin extends Plugin implements LayerChangeListener
 {
     private LiveGpsAcquirer acquirer = null;
@@ -34,6 +36,5 @@
 
     private GpxData data = new GpxData();
-    private LiveGpsLayer lgpslayer;
-
+    private LiveGpsLayer lgpslayer = null;
 
     public class CaptureAction extends JosmAction {
@@ -74,4 +75,21 @@
                 setAutoCenter(lgpsautocenter.isSelected());
             }
+        }
+    }
+
+    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+    }
+
+    public void layerAdded(Layer newLayer) {
+    }
+
+    public void layerRemoved(Layer oldLayer) {
+        if(oldLayer == lgpslayer)
+        {
+            enableTracking(false);
+            lgpscapture.setSelected(false);
+            removePropertyChangeListener(lgpslayer);
+            Layer.listeners.remove(this);
+            lgpslayer = null;
         }
     }
@@ -135,4 +153,5 @@
                     lgpslayer = new LiveGpsLayer(data);
                     Main.main.addLayer(lgpslayer);
+                    Layer.listeners.add(this);
                     lgpslayer.setAutoCenter(isAutoCenter());
                 }
@@ -170,4 +189,14 @@
     }
 
+    /**
+     * Remove a listener for gps events.
+     * @param listener the listener.
+     */
+    public void removePropertyChangeListener(PropertyChangeListener listener) {
+        if(acquirer != null)
+            acquirer.removePropertyChangeListener(listener);
+        else if(listenerQueue != null && listenerQueue.contains(listener))
+            listenerQueue.remove(listener);
+    }
 
     /* (non-Javadoc)
@@ -184,5 +213,4 @@
     }
 
-
     /**
      * @return the lgpsmenu
@@ -191,5 +219,3 @@
         return this.lgpsmenu;
     }
-
 }
-
