Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/FrequenceExtractor.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/FrequenceExtractor.java	(revision 32319)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/FrequenceExtractor.java	(revision 32320)
@@ -1,7 +1,4 @@
 package org.openstreetmap.josm.plugins.extractor;
 
-import org.openstreetmap.josm.plugins.container.OSMNode;
-import org.openstreetmap.josm.plugins.container.OSMRelation;
-import org.openstreetmap.josm.plugins.container.OSMWay;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -9,7 +6,12 @@
 import java.util.List;
 import java.util.Map;
+
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.plugins.container.OSMNode;
+import org.openstreetmap.josm.plugins.container.OSMRelation;
+import org.openstreetmap.josm.plugins.container.OSMWay;
+import org.openstreetmap.josm.tools.Utils;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
@@ -50,18 +52,10 @@
 
     public void parseDocument() {
-        // parse
-        System.out.println("extracting frequencies...");
-        SAXParserFactory factory = SAXParserFactory.newInstance();
+        Main.info("extracting frequencies...");
         try {
-            SAXParser parser = factory.newSAXParser();
-            parser.parse(osmXmlFileName, this);
-        } catch (ParserConfigurationException e) {
-            System.out.println("ParserConfig error " + e);
-        } catch (SAXException e) {
-            System.out.println("SAXException : xml not well formed " + e);
-        } catch (IOException e) {
-            System.out.println("IO error " + e);
-        }
-    //LOG.info("Frequencies from OSM/XML file parsed!");    
+            Utils.newSafeSAXParser().parse(osmXmlFileName, this);
+        } catch (ParserConfigurationException | IOException | SAXException e) {
+            Main.error(e);
+        }
     }
 
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java	(revision 32319)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/extractor/LanguageDetector.java	(revision 32320)
@@ -1,14 +1,17 @@
 package org.openstreetmap.josm.plugins.extractor;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.tools.Utils;
 
 import com.cybozu.labs.langdetect.Detector;
 import com.cybozu.labs.langdetect.DetectorFactory;
 import com.cybozu.labs.langdetect.LangDetectException;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 /**
@@ -26,5 +29,4 @@
 
     public static LanguageDetector getInstance(String languageProfilesPath) {
-        //System.out.println("language profile path: \n" + languageProfilesPath + "/el");
         if (languageDetector == null) {
             languageDetector = new LanguageDetector();
@@ -52,6 +54,5 @@
 
         if (!new File(languageProfilesPath).exists()) {
-            //new File(languageProfilesPath).mkdir();
-            new File(languageProfilesPath).mkdirs();
+            Utils.mkDirs(new File(languageProfilesPath));
         }
         
@@ -67,5 +68,4 @@
 
         try {
-
             languageProfilesOutputFileEl.createNewFile();
             languageProfilesOutputFileEn.createNewFile();
@@ -77,109 +77,29 @@
             languageProfilesOutputFileZh.createNewFile();
             languageProfilesOutputFileHi.createNewFile();
-            
         } catch (IOException ex) {
             Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
-        }
-
-        FileOutputStream outputStreamEl = null;
-        FileOutputStream outputStreamEn = null;
-        FileOutputStream outputStreamDe = null;
-        FileOutputStream outputStreamFr = null;
-        FileOutputStream outputStreamEs = null;
-        FileOutputStream outputStreamRu = null;
-        FileOutputStream outputStreamTr = null;
-        FileOutputStream outputStreamZh = null;
-        FileOutputStream outputStreamHi = null;
-        
-        try {
-            
-            outputStreamEl = new FileOutputStream(languageProfilesOutputFileEl);
-            outputStreamEn = new FileOutputStream(languageProfilesOutputFileEn);
-            outputStreamDe = new FileOutputStream(languageProfilesOutputFileDe);
-            outputStreamFr = new FileOutputStream(languageProfilesOutputFileFr);
-            outputStreamEs = new FileOutputStream(languageProfilesOutputFileEs);
-            outputStreamRu = new FileOutputStream(languageProfilesOutputFileRu);
-            outputStreamTr = new FileOutputStream(languageProfilesOutputFileTr);
-            outputStreamZh = new FileOutputStream(languageProfilesOutputFileZh);
-            outputStreamHi = new FileOutputStream(languageProfilesOutputFileHi);
-            
-        } catch (FileNotFoundException ex) {
-            Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
-        }
-
-        int read = 0;
-        byte[] bytes = new byte[1024];
-        try {
-
-            while ((read = languageProfilesInputStreamEl.read(bytes)) != -1) {
-                outputStreamEl.write(bytes, 0, read);
-            }
-
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamEn.read(bytes)) != -1) {
-                outputStreamEn.write(bytes, 0, read);
-            }
-
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamDe.read(bytes)) != -1) {
-                outputStreamDe.write(bytes, 0, read);
-            }
-
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamFr.read(bytes)) != -1) {
-                outputStreamFr.write(bytes, 0, read);
-            }
-            
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamEs.read(bytes)) != -1) {
-                outputStreamEs.write(bytes, 0, read);
-            }  
-            
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamRu.read(bytes)) != -1) {
-                outputStreamRu.write(bytes, 0, read);
-            } 
-
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamTr.read(bytes)) != -1) {
-                outputStreamTr.write(bytes, 0, read);
-            } 
-            
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamZh.read(bytes)) != -1) {
-                outputStreamZh.write(bytes, 0, read);
-            }
-            
-            read = 0;
-            bytes = new byte[1024];
-
-            while ((read = languageProfilesInputStreamHi.read(bytes)) != -1) {
-                outputStreamHi.write(bytes, 0, read);
-            } 
-            
-        } catch (IOException ex) {
-            Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
+            Main.error(ex);
         }
 
         try {
+        	Files.copy(languageProfilesInputStreamEl, languageProfilesOutputFileEl.toPath());
+        	Files.copy(languageProfilesInputStreamEn, languageProfilesOutputFileEn.toPath());
+        	Files.copy(languageProfilesInputStreamDe, languageProfilesOutputFileDe.toPath());
+        	Files.copy(languageProfilesInputStreamFr, languageProfilesOutputFileFr.toPath());
+        	Files.copy(languageProfilesInputStreamEs, languageProfilesOutputFileEs.toPath());
+        	Files.copy(languageProfilesInputStreamRu, languageProfilesOutputFileRu.toPath());
+        	Files.copy(languageProfilesInputStreamTr, languageProfilesOutputFileTr.toPath());
+        	Files.copy(languageProfilesInputStreamZh, languageProfilesOutputFileZh.toPath());
+        	Files.copy(languageProfilesInputStreamHi, languageProfilesOutputFileHi.toPath());
+        } catch (IOException ex) {
+            Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
+            Main.error(ex);
+        }
 
+        try {
             DetectorFactory.loadProfile(languageProfilesPath);
-
         } catch (LangDetectException ex) {
             Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
+            Main.error(ex);
         }
     }
@@ -189,9 +109,8 @@
             Detector detector = DetectorFactory.create();
             detector.append(text);
-            String lang = detector.detect();
-            //System.out.println("language detected: " + lang);
-            return lang;
+            return detector.detect();
         } catch (LangDetectException ex) {
             Logger.getLogger(LanguageDetector.class.getName()).log(Level.SEVERE, null, ex);
+            Main.error(ex);
             return "en"; //default lang to return if anything goes wrong at detection
         }
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/HistoryParser.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/HistoryParser.java	(revision 32319)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/personalization/HistoryParser.java	(revision 32320)
@@ -1,31 +1,17 @@
-
 package org.openstreetmap.josm.plugins.osmrec.personalization;
 
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+
 import javax.xml.parsers.ParserConfigurationException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
+
 import org.geotools.geometry.jts.JTS;
 import org.geotools.referencing.CRS;
@@ -37,7 +23,21 @@
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.io.OsmApi;
 import org.openstreetmap.josm.plugins.container.OSMNode;
 import org.openstreetmap.josm.plugins.container.OSMWay;
-
+import org.openstreetmap.josm.tools.HttpClient;
+import org.openstreetmap.josm.tools.Utils;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
 
 /**
@@ -46,8 +46,6 @@
  * @author imis-nkarag
  */
-
 public class HistoryParser {
-    private static final String OSM_API = "http://api.openstreetmap.org/api/0.6/";
-    //private static final String GET_CHANGESET = "http://api.openstreetmap.org/api/0.6/changeset/28851695/download";
+    private static final String OSM_API = OsmApi.getOsmApi().getBaseUrl();
     private static final CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84;
     private static final CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN;
@@ -62,4 +60,8 @@
     private final String username;
 
+    /**
+     * Constructs a new {@code HistoryParser}.
+     * @param username user name
+     */
     public HistoryParser(String username) {   
         this.username = username;
@@ -81,44 +83,20 @@
         try {
             String osmUrl = OSM_API + "changesets?display_name=" + username + "&time=" + timeInterval;
-            
-            System.out.println("requesting..\n" + osmUrl);
-            
-            URL url = new URL(osmUrl);
-            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-            connection.setRequestMethod("GET");
-            //connection.setRequestProperty("Accept", "application/xml");
-            
-            InputStream xml = connection.getInputStream();
-            //System.out.println("xml" + xml.read());
-            
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            DocumentBuilder db = dbf.newDocumentBuilder(); 
-            Document doc = db.parse(xml);
-            NodeList nodes = doc.getElementsByTagName("changeset");
-   
-            
-            System.out.println("changeset size "+ nodes.getLength());
-            //System.out.println("changeset ");
+            InputStream xml = HttpClient.create(new URL(osmUrl)).connect().getContent();
+            NodeList nodes = Utils.parseSafeDOM(xml).getElementsByTagName("changeset");
+
+            Main.debug("changeset size "+ nodes.getLength());
             for (int i = 0; i < nodes.getLength(); i++) {
-                //Element element = (Element) nodes.item(i);
-                System.out.println("attributes of " + i + "th changeset"); 
-                //for(int j = 0; j < nodes.item(i).getAttributes().getLength(); j++){
-                    //System.out.println("-  "+ nodes.item(i).getAttributes().item(j));
-                    
-                //}
+            	Main.debug("attributes of " + i + "th changeset"); 
                 String id = nodes.item(i).getAttributes().item(3).toString();
-                System.out.println("id:" + nodes.item(i).getAttributes().item(3));
+                Main.debug("id:" + nodes.item(i).getAttributes().item(3));
                 id = stripQuotes(id);
                 changesetIDsList.add(id);                
             }
-            
+
             for(String id : changesetIDsList){
                 getChangesetByID(id);
             }
-        } catch (MalformedURLException ex) {
-            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (IOException ex) {
-            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (ParserConfigurationException | SAXException ex) {
+        } catch (IOException | ParserConfigurationException | SAXException ex) {
             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
         }
@@ -128,20 +106,6 @@
         try {
             String changesetByIDURL = OSM_API+ "changeset/" + id + "/download";
-            
-            System.out.println("requesting..\n" + changesetByIDURL);
-            
-            URL url = new URL(changesetByIDURL);
-            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-            connection.setRequestMethod("GET");
-            //connection.setRequestProperty("Accept", "application/xml");
-        
-            InputStream xml = connection.getInputStream();
-            
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            DocumentBuilder db = dbf.newDocumentBuilder(); 
-            Document doc = db.parse(xml);
-            //NodeList nodes = doc.getElementsByTagName("create");
-            //NodeList nodes2 = doc.getChildNodes();
-            Node osmChange = doc.getFirstChild();
+            InputStream xml = HttpClient.create(new URL(changesetByIDURL)).connect().getContent();
+            Node osmChange = Utils.parseSafeDOM(xml).getFirstChild();
   
             //get all nodes first, in order to be able to call all nodes references and create the geometries
@@ -155,8 +119,6 @@
 
                     if(osmObject.getNodeName().equals("node")){
-                        //System.out.println("node");
                         //node data 
                         nodeTmp = new OSMNode();
-                        //System.out.println("id of node: " + wayChild.getAttributes().getNamedItem("id").getNodeValue());
                         nodeTmp.setID(osmObject.getAttributes().getNamedItem("id").getNodeValue());
 
@@ -178,5 +140,4 @@
                         nodeList.add(nodeTmp);
                         nodesWithIDs.put(nodeTmp.getID(), nodeTmp);
-
                     }                        
                 }
@@ -186,5 +147,4 @@
                 String changeType = osmChange.getChildNodes().item(i).getNodeName();
                 if(!(changeType.equals("#text") || changeType.equals("delete"))){
-                //if(!(changeType.equals("#text"))){
                     NodeList changeChilds = osmChange.getChildNodes().item(i).getChildNodes();
 
@@ -196,6 +156,5 @@
                         wayTmp.setID(osmObject.getAttributes().getNamedItem("id").getNodeValue());  
                         //osmObject.getChildNodes() <-extract tags, then set tags to osm object
-                        System.out.println("\n\nWAY: " + wayTmp.getID());
-                        //System.out.println("i " + i + " j " + j + " wayTmp refers: " + wayTmp.getNodeReferences());
+                        Main.debug("\n\nWAY: " + wayTmp.getID());
                         for(int l=0; l<osmObject.getChildNodes().getLength(); l++){
                             String wayChild = osmObject.getChildNodes().item(l).getNodeName();
@@ -208,7 +167,5 @@
                             }
                             else if(wayChild.equals("nd")){
-                                //System.out.println("nd ref: " + osmObject.getChildNodes().item(j).getAttributes().getNamedItem("ref").getNodeValue());
                                 wayTmp.addNodeReference(osmObject.getChildNodes().item(l).getAttributes().getNamedItem("ref").getNodeValue());
-
                             }
                         }
@@ -216,16 +173,12 @@
                         //construct the Way geometry from each node of the node references
                         List<String> references = wayTmp.getNodeReferences();
-                        //System.out.println("references exist? size: " + references.size());  
 
                         for (String entry: references) {
                            if(nodesWithIDs.containsKey(entry)){ 
-                            //System.out.println("nodes with ids, entry " + entry);
-                            //System.out.println("nodes with ids: " + nodesWithIDs);
                                 Geometry geometry = nodesWithIDs.get(entry).getGeometry(); //get the geometry of the node with ID=entry
                                 wayTmp.addNodeGeometry(geometry); //add the node geometry in this way
-                           //}
                            }
                            else{
-                               System.out.println("nodes with ids, no entry " + entry);
+                               Main.debug("nodes with ids, no entry " + entry);
                                getNodeFromAPI(entry);
                            }
@@ -233,5 +186,4 @@
 
                         Geometry geom = geometryFactory.buildGeometry(wayTmp.getNodeGeometries());
-                        //System.out.println("geom: " + geom);
                         if((wayTmp.getNodeGeometries().size()>3) && 
                                 wayTmp.getNodeGeometries().get(0).equals(wayTmp.getNodeGeometries()
@@ -256,5 +208,5 @@
                         //it is an open geometry with more than one nodes, make it linestring 
 
-                            LineString lineString =  geometryFactory.createLineString(geom.getCoordinates());
+                            LineString lineString = geometryFactory.createLineString(geom.getCoordinates());
                             wayTmp.setGeometry(lineString);               
                         }
@@ -268,10 +220,5 @@
                 }
             }                  
-            
-        } catch (MalformedURLException ex) {
-            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (IOException ex) {
-            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (ParserConfigurationException | SAXException ex) {
+        } catch (IOException | ParserConfigurationException | SAXException ex) {
             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
         }   
@@ -279,7 +226,5 @@
 
     private String stripQuotes(String id) {
-        id = id.substring(4, id.length()-1);
-        //System.out.println("id: " + id);
-        return id;
+        return id.substring(4, id.length()-1);
     }
 
@@ -287,22 +232,8 @@
         try {
             String osmUrl = OSM_API + "node/" + nodeID;
-            
-            System.out.println("requesting..\n" + osmUrl);
-            
-            URL url = new URL(osmUrl);
-            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-            connection.setRequestMethod("GET");
-            //connection.setRequestProperty("Accept", "application/xml");
-            
-            InputStream xml = connection.getInputStream();
-            //System.out.println("xml" + xml.read());
-            
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            DocumentBuilder db = dbf.newDocumentBuilder();
-            Document doc = db.parse(xml);
-            NodeList nodes = doc.getElementsByTagName("node");
+            InputStream xml = HttpClient.create(new URL(osmUrl)).connect().getContent();
+            NodeList nodes = Utils.parseSafeDOM(xml).getElementsByTagName("node");
             String lat = nodes.item(0).getAttributes().getNamedItem("lat").getNodeValue();
             String lon = nodes.item(0).getAttributes().getNamedItem("lon").getNodeValue();
-            //System.out.println("lat from api " + lat);
             
             nodeTmp = new OSMNode();
@@ -327,9 +258,5 @@
             nodesWithIDs.put(nodeTmp.getID(), nodeTmp);
             
-        } catch (MalformedURLException ex) {
-            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (IOException ex) {
-            Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
-        } catch (ParserConfigurationException | SAXException ex) {
+        } catch (IOException | ParserConfigurationException | SAXException ex) {
             Logger.getLogger(HistoryParser.class.getName()).log(Level.SEVERE, null, ex);
         }
Index: /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/OSMParser.java
===================================================================
--- /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/OSMParser.java	(revision 32319)
+++ /applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/parsers/OSMParser.java	(revision 32320)
@@ -1,14 +1,4 @@
 package org.openstreetmap.josm.plugins.parsers;
 
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.GeometryFactory;
-import com.vividsolutions.jts.geom.LineString;
-import com.vividsolutions.jts.geom.LinearRing;
-import com.vividsolutions.jts.geom.Point;
-import com.vividsolutions.jts.geom.Polygon;
-import org.openstreetmap.josm.plugins.container.OSMNode;
-import org.openstreetmap.josm.plugins.container.OSMRelation;
-import org.openstreetmap.josm.plugins.container.OSMWay;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -18,7 +8,7 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
+
 import org.geotools.geometry.jts.JTS;
 import org.geotools.referencing.CRS;
@@ -30,7 +20,20 @@
 import org.opengis.referencing.operation.MathTransform;
 import org.opengis.referencing.operation.TransformException;
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.plugins.container.OSMNode;
+import org.openstreetmap.josm.plugins.container.OSMRelation;
+import org.openstreetmap.josm.plugins.container.OSMWay;
+import org.openstreetmap.josm.tools.Utils;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
+
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
+import com.vividsolutions.jts.geom.LineString;
+import com.vividsolutions.jts.geom.LinearRing;
+import com.vividsolutions.jts.geom.Point;
+import com.vividsolutions.jts.geom.Polygon;
 
 /**
@@ -39,5 +42,4 @@
  * @author imis-nkarag
  */
-
 public class OSMParser extends DefaultHandler {
     
@@ -62,5 +64,4 @@
     
     public OSMParser(String osmXmlFileName)  {
-        //System.out.println("creating osmParser..");
         this.osmXmlFileName = osmXmlFileName;       
         nodeList = new ArrayList<>();
@@ -73,22 +74,12 @@
             Logger.getLogger(OSMParser.class.getName()).log(Level.SEVERE, null, ex);
         }
-        //System.out.println("osmParser created!");
     }
 
     public void parseDocument() {
-        // parse        
-        System.out.println("parsing OSM file...");
-        SAXParserFactory factory = SAXParserFactory.newInstance();
         try {
-            SAXParser parser = factory.newSAXParser();
-            parser.parse(osmXmlFileName, this);
-        } catch (ParserConfigurationException e) {
-            System.out.println("ParserConfig error " + e);
-        } catch (SAXException e) {
-            System.out.println("SAXException : xml not well formed " + e);
-        } catch (IOException e) {
-            System.out.println("IO error " + e);
-        }
-    //LOG.info("Instances from OSM/XML file parsed!");    
+            Utils.newSafeSAXParser().parse(osmXmlFileName, this);
+        } catch (ParserConfigurationException | SAXException | IOException e) {
+            Main.error(e);
+        }
     }
 
@@ -130,5 +121,4 @@
                 wayTmp.setUser("undefined");
             }
-            //System.out.println("way user: " + attributes.getValue("user"));
                     
             inWay = true;
@@ -211,5 +201,5 @@
                 wayTmp.setGeometry(point);
             }
-        wayList.add(wayTmp);
+            wayList.add(wayTmp);
         } 
         
