Index: /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SortPTRouteMembersAction.java
===================================================================
--- /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SortPTRouteMembersAction.java	(revision 33511)
+++ /applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/actions/SortPTRouteMembersAction.java	(revision 33512)
@@ -105,4 +105,5 @@
         }
 
+        //first loop trough all the members and remove the roles
         List<RelationMember> members = new ArrayList<>();
         List<RelationMember> oldMembers = rel.getMembers();
@@ -115,6 +116,10 @@
             rel.removeMember(0);
         }
+
+        //sort the members with the built in sorting function in order to get
+        //the continuity of the ways
         members = new RelationSorter().sortMembers(members);
 
+        //divide stops and ways
         List<RelationMember> stops = new ArrayList<>();
         List<RelationMember> wayMembers = new ArrayList<>();
@@ -131,5 +136,9 @@
         }
 
-        Map<String, PTStop> stopsByName = new HashMap<>();
+        //couple together stop positions and platforms that are part of the same
+        //stop. the only way used to determine whether they are part of the same
+        //stop or not is the name. this should be improved by using also the
+        //distance
+        Map<String, List<PTStop>> stopsByName = new HashMap<>();
         List<PTStop> unnamed = new ArrayList<>();
         stops.forEach(rm -> {
@@ -137,7 +146,14 @@
             if (name != null) {
                 if (!stopsByName.containsKey(name))
-                    stopsByName.put(name, new PTStop(rm));
-                else
-                    stopsByName.get(name).addStopElement(rm);
+                    stopsByName.put(name, new ArrayList<>());
+                List<PTStop> ls = stopsByName.get(name);
+                if (ls.isEmpty()) {
+                    ls.add(new PTStop(rm));
+                } else {
+                    PTStop stp = ls.get(ls.size() - 1);
+                    if (!stp.addStopElement(rm)) {
+                        ls.add(new PTStop(rm));
+                    }
+                }
             } else {
                 unnamed.add(new PTStop(rm));
@@ -145,6 +161,9 @@
         });
 
+        //assign to each stop the corresponding way. if none is found add already
+        //the stop to the relation since it is not possible to reason on the order
         StopToWayAssigner assigner = new StopToWayAssigner(ways);
-        List<PTStop> ptstops = new ArrayList<>(stopsByName.values());
+        List<PTStop> ptstops = new ArrayList<>();
+        stopsByName.values().forEach(ptstops::addAll);
         Map<Way, List<PTStop>> wayStop = new HashMap<>();
         ptstops.forEach(stop -> {
@@ -168,4 +187,5 @@
         });
 
+        //based on the order of the ways, add the stops to the relation
         for (int i = 0; i < wayMembers.size(); i++) {
             RelationMember wm = wayMembers.get(i);
@@ -187,4 +207,6 @@
                 List<PTStop> stps = wayStop.get(curr);
                 if (stps != null) {
+                    //if for one way there are more than one stop assigned to it,
+                    //another sorting step is needed
                     if (stps.size() > 1)
                         stps = sortSameWayStops(stps, curr, prev, next);
@@ -208,4 +230,6 @@
     }
 
+    //sorts the stops that are assigned to the same way. this is done based on
+    //the distance from the previous way.
     private static List<PTStop> sortSameWayStops(List<PTStop> stps, Way way, Way prev, Way next) {
         Map<Node, List<PTStop>> closeNodes = new HashMap<>();
