diff --git a/include/osm/osm_road_segment.h b/include/osm/osm_road_segment.h
index 98c39bb41f9477d6fb84b8e465d07b8b15630cda..b0108a1358d1d88eea36ec32bf5800f30ffd2276 100644
--- a/include/osm/osm_road_segment.h
+++ b/include/osm/osm_road_segment.h
@@ -25,8 +25,8 @@ class COSMRoadSegment
   protected:
     void set_start_distance(double dist);
     void set_end_distance(double dist);
-    void generate_fwd_geometry(CRoad *road,double resolution);
-    void generate_bwd_geometry(CRoad *road,double resolution);
+    bool generate_fwd_geometry(CRoad *road,double resolution);
+    bool generate_bwd_geometry(CRoad *road,double resolution);
     void convert(CRoad **left_road,CRoad **right_road,double resolution);
   public:
     COSMRoadSegment(COSMWay *way);
diff --git a/src/osm/osm_map.cpp b/src/osm/osm_map.cpp
index 804e9f9f72f01599636666f1960d3c9bc671e8c4..9111591348dec3c4053c7925955cb4aebbf50c4e 100644
--- a/src/osm/osm_map.cpp
+++ b/src/osm/osm_map.cpp
@@ -350,8 +350,11 @@ void COSMMap::convert(CRoadMap &road)
       road.add_road(left_road);
       segment_roads.push_back(left_road);
     }
-    map_pair=std::make_pair(this->segments[i],segment_roads);
-    road_map.push_back(map_pair);    
+    if(right_road!=NULL || left_road!=NULL)
+    {
+      map_pair=std::make_pair(this->segments[i],segment_roads);
+      road_map.push_back(map_pair);    
+    }
   }
   for(unsigned int i=0;i<this->junctions.size();i++)
   {
diff --git a/src/osm/osm_node.cpp b/src/osm/osm_node.cpp
index 5c61a6e611a5b82c9b09aadbfafa863bab5919cb..b9f026254648704844b5a71fb53ab0e88d92a68d 100644
--- a/src/osm/osm_node.cpp
+++ b/src/osm/osm_node.cpp
@@ -143,14 +143,14 @@ void COSMNode::split_ways(void)
 
 void COSMNode::remove_in_junction_nodes(void)
 {
-  double width,width2,dist,x,y,heading,length,start_x,start_y,end_x,end_y,cross;
+  double width,width2,dist,x,y,heading,length,start_x,start_y,end_x,end_y,cross,angle;
   COSMNode *check_node,*node1,*node2;
 
   if(this->ways.size()>1)
   {
     for(unsigned int i=0;i<this->ways.size();i++)
     {
-      width=std::max(this->ways[i]->get_num_forward_lanes(),this->ways[i]->get_num_backward_lanes())*this->ways[i]->get_lane_width();
+      width=this->ways[i]->get_num_lanes()*this->ways[i]->get_lane_width()/2.0;
       if(this->ways[i]->is_node_first(this->id))
       {
         node1=(COSMNode *)&this->ways[i]->get_segment_end_node(FIRST_SEGMENT);
@@ -158,8 +158,8 @@ void COSMNode::remove_in_junction_nodes(void)
       }
       else
       {
-        node1=(COSMNode *)&this->ways[i]->get_segment_end_node(LAST_SEGMENT);
-        node2=(COSMNode *)&this->ways[i]->get_segment_start_node(LAST_SEGMENT);
+        node2=(COSMNode *)&this->ways[i]->get_segment_end_node(LAST_SEGMENT);
+        node1=(COSMNode *)&this->ways[i]->get_segment_start_node(LAST_SEGMENT);
       }
       node1->get_location(start_x,start_y);
       node2->get_location(end_x,end_y);
@@ -172,25 +172,29 @@ void COSMNode::remove_in_junction_nodes(void)
             check_node=(COSMNode *)&this->ways[j]->get_segment_end_node(FIRST_SEGMENT);
           else
             check_node=(COSMNode *)&this->ways[j]->get_segment_start_node(LAST_SEGMENT);
-          width2=std::max(this->ways[j]->get_num_forward_lanes(),this->ways[j]->get_num_backward_lanes())*this->ways[j]->get_lane_width();
-          heading=this->compute_heading(*check_node);
-          check_node->get_location(x,y);
-          x=x-width2*sin(heading);
-          y=y+width2*cos(heading);
-          cross=(x-start_x)*(end_y-start_y)-(y-start_y)*(end_x-start_x);
-          dist=fabs(cross)/length;
-          if(dist<width)
+          angle=this->compute_angle(*node1,*check_node);
+          if(fabs(angle)<1.5707)
           {
-            this->ways[j]->delete_node(check_node);
-            continue;
+            width2=this->ways[j]->get_num_lanes()*this->ways[j]->get_lane_width()/2.0;
+            heading=this->compute_heading(*check_node);
+            check_node->get_location(x,y);
+            x=x-width2*sin(heading);
+            y=y+width2*cos(heading);
+            cross=(x-start_x)*(end_y-start_y)-(y-start_y)*(end_x-start_x);
+            dist=fabs(cross)/length;
+            if(dist<width)
+            {
+              this->ways[j]->delete_node(check_node);
+              continue;
+            }
+            check_node->get_location(x,y);
+            x=x+width2*sin(heading);
+            y=y-width2*cos(heading);
+            cross=(x-start_x)*(end_y-start_y)-(y-start_y)*(end_x-start_x);
+            dist=fabs(cross)/length;
+            if(dist<width)
+              this->ways[j]->delete_node(check_node);
           }
-          check_node->get_location(x,y);
-          x=x+width2*sin(heading);
-          y=y-width2*cos(heading);
-          cross=(x-start_x)*(end_y-start_y)-(y-start_y)*(end_x-start_x);
-          dist=fabs(cross)/length;
-          if(dist<width)
-            this->ways[j]->delete_node(check_node);
         }
       }
     }
diff --git a/src/osm/osm_road_segment.cpp b/src/osm/osm_road_segment.cpp
index d2fd30449fc717cc39e356966cc83d2ed4ab513a..d92ecec82974a64cd843864d3f5d31c2268886fb 100644
--- a/src/osm/osm_road_segment.cpp
+++ b/src/osm/osm_road_segment.cpp
@@ -87,10 +87,10 @@ void COSMRoadSegment::set_end_distance(double dist)
   }
 }
 
-void COSMRoadSegment::generate_fwd_geometry(CRoad *road,double resolution)
+bool COSMRoadSegment::generate_fwd_geometry(CRoad *road,double resolution)
 {
   double heading1,heading2,x,y,angle,length1,dist,prev_dist,y_offset;
-  double angle2,angle3,prev_heading;
+//  double angle2,angle3,prev_heading;
   TPoint start_point,end_point;
   COSMNode *node1,*node2,*node3;
 
@@ -112,13 +112,15 @@ void COSMRoadSegment::generate_fwd_geometry(CRoad *road,double resolution)
       start_point.heading=heading1;
       start_point.curvature=0.0;
       road->set_start_point(start_point);
-      prev_heading=heading1;
+      //prev_heading=heading1;
     }
     if((i+1)==(this->parent_way->get_num_nodes()-1))// straight line
     {
-      angle2=atan2(y_offset,length1-this->end_distance);
-      angle3=diff_angle(heading1,prev_heading)+angle2;
-      if(fabs(angle3)<1.5707)
+//      angle2=atan2(y_offset,length1-this->end_distance);
+//      angle3=diff_angle(heading1,prev_heading)+angle2;
+//      if(fabs(angle3)<1.5707)
+//      {
+      if((length1-this->end_distance-prev_dist)>0.0)
       {
         end_point.x=x+(length1-this->end_distance)*cos(heading1)-y_offset*sin(heading1);
         end_point.y=y+(length1-this->end_distance)*sin(heading1)+y_offset*cos(heading1);    
@@ -126,6 +128,7 @@ void COSMRoadSegment::generate_fwd_geometry(CRoad *road,double resolution)
         end_point.curvature=0.0;
         road->add_segment(end_point);
       }
+//      }
     }
     else 
     {
@@ -144,17 +147,17 @@ void COSMRoadSegment::generate_fwd_geometry(CRoad *road,double resolution)
           start_point.curvature=0.0;
           road->set_start_point(start_point);
           prev_dist=0.0;
-          prev_heading=heading2;
+          //prev_heading=heading2;
         }
         else if((i+2)==(this->parent_way->get_num_nodes()-1))
         {
           prev_dist=dist;
-          prev_heading=heading2;
+          //prev_heading=heading2;
         }
         else
         {
           prev_dist=dist;
-          prev_heading=heading1;
+          //prev_heading=heading1;
         }
         continue;
       }
@@ -176,15 +179,19 @@ void COSMRoadSegment::generate_fwd_geometry(CRoad *road,double resolution)
       end_point.curvature=0.0;
       road->add_segment(end_point);
       prev_dist=dist;
-      prev_heading=heading1;
+//      prev_heading=heading1;
     } 
   }
+  if(road->get_num_segments()==0)
+    return false;
+  else
+    return true;
 }
 
-void COSMRoadSegment::generate_bwd_geometry(CRoad *road,double resolution)
+bool COSMRoadSegment::generate_bwd_geometry(CRoad *road,double resolution)
 {
   double heading1,heading2,x,y,angle,length1,dist,prev_dist,y_offset;
-  double angle2,angle3,prev_heading;
+//  double angle2,angle3,prev_heading;
   TPoint start_point,end_point;
   COSMNode *node1,*node2,*node3;
 
@@ -206,13 +213,15 @@ void COSMRoadSegment::generate_bwd_geometry(CRoad *road,double resolution)
       start_point.heading=heading1;
       start_point.curvature=0.0;
       road->set_start_point(start_point);
-      prev_heading=heading1;
+      //prev_heading=heading1;
     }
     if((i-1)==0)// straight line
     {
-      angle2=atan2(y_offset,length1-this->end_distance);
-      angle3=diff_angle(heading1,prev_heading)+angle2;
-      if(fabs(angle3)<1.5707)
+//      angle2=atan2(y_offset,length1-this->end_distance);
+//      angle3=diff_angle(heading1,prev_heading)+angle2;
+//      if(fabs(angle3)<1.5707)
+//      {
+      if((length1-this->start_distance-prev_dist)>0.0)
       {
         end_point.x=x+(length1-this->start_distance)*cos(heading1)-y_offset*sin(heading1);
         end_point.y=y+(length1-this->start_distance)*sin(heading1)+y_offset*cos(heading1);
@@ -220,6 +229,7 @@ void COSMRoadSegment::generate_bwd_geometry(CRoad *road,double resolution)
         end_point.curvature=0.0;
         road->add_segment(end_point);
       }
+//      }
     }
     else 
     {
@@ -238,17 +248,17 @@ void COSMRoadSegment::generate_bwd_geometry(CRoad *road,double resolution)
           start_point.curvature=0.0;
           road->set_start_point(start_point);
           prev_dist=0.0;
-          prev_heading=heading2;
+          //prev_heading=heading2;
         }
         else if((i-2)==0)
         {
           prev_dist=dist;
-          prev_heading=heading2;
+          //prev_heading=heading2;
         }
         else
         {
           prev_dist=dist;
-          prev_heading=heading1;
+          //prev_heading=heading1;
         }
         continue;
       }
@@ -270,9 +280,13 @@ void COSMRoadSegment::generate_bwd_geometry(CRoad *road,double resolution)
       end_point.curvature=0.0;
       road->add_segment(end_point);
       prev_dist=dist;
-      prev_heading=heading1;
+      //prev_heading=heading1;
     } 
   }
+  if(road->get_num_segments()==0)
+    return false;
+  else
+    return true;
 }
 
 void COSMRoadSegment::convert(CRoad **left_road,CRoad **right_road,double resolution)
@@ -290,28 +304,35 @@ void COSMRoadSegment::convert(CRoad **left_road,CRoad **right_road,double resolu
     (*right_road)->set_num_lanes(num_lanes);
     (*right_road)->set_lane_width(lane_width);
     // generate geometry
-    this->generate_fwd_geometry(*right_road,resolution);
-    // generate connectivity
-    for(unsigned int i=0;i<(*right_road)->get_num_segments();i++)
+    if(this->generate_fwd_geometry(*right_road,resolution))
     {
-      segment=(*right_road)->get_segment_by_index(i);
-      for(unsigned int j=0;j<num_lanes;j++)
+      // generate connectivity
+      for(unsigned int i=0;i<(*right_road)->get_num_segments();i++)
       {
-        restrictions=this->get_parent_way().get_lane_restriction(this->get_parent_way().get_num_forward_lanes()-j-1);
-        if(restrictions&RESTRICTION_RIGHT)
+        segment=(*right_road)->get_segment_by_index(i);
+        for(unsigned int j=0;j<num_lanes;j++)
         {
-          for(unsigned int k=j+1;k<num_lanes;k++)
-            segment->unlink_lanes(j,k);
+          restrictions=this->get_parent_way().get_lane_restriction(this->get_parent_way().get_num_forward_lanes()-j-1);
+          if(restrictions&RESTRICTION_RIGHT)
+          {
+            for(unsigned int k=j+1;k<num_lanes;k++)
+              segment->unlink_lanes(j,k);
+          }
+          if(restrictions&RESTRICTION_LEFT)
+          {
+            for(unsigned int k=0;k<j;k++)
+              segment->unlink_lanes(j,k);
+          }   
+//          if(restrictions&RESTRICTION_THROUGH)
+//            segment->unlink_lanes(j,j);
         }
-        if(restrictions&RESTRICTION_LEFT)
-        {
-          for(unsigned int k=0;k<j;k++)
-            segment->unlink_lanes(j,k);
-        }  
-//        if(restrictions&RESTRICTION_THROUGH)
-//          segment->unlink_lanes(j,j);
       }
     }
+    else
+    {
+      delete (*right_road);
+      (*right_road)=NULL;
+    }
   }
   else
     (*right_road)=NULL;
@@ -322,28 +343,35 @@ void COSMRoadSegment::convert(CRoad **left_road,CRoad **right_road,double resolu
     (*left_road)->set_num_lanes(num_lanes);
     (*left_road)->set_lane_width(lane_width);
     // generate geometry
-    this->generate_bwd_geometry(*left_road,resolution);
-    // generate connectivity
-    for(unsigned int i=0;i<(*left_road)->get_num_segments();i++)
+    if(this->generate_bwd_geometry(*left_road,resolution))
     {
-      segment=(*left_road)->get_segment_by_index(i);
-      for(unsigned int j=0;j<num_lanes;j++)
+      // generate connectivity
+      for(unsigned int i=0;i<(*left_road)->get_num_segments();i++)
       {
-        restrictions=this->get_parent_way().get_lane_restriction(j+this->get_parent_way().get_num_forward_lanes());
-        if(restrictions&RESTRICTION_RIGHT)
-        {
-          for(unsigned int k=j+1;k<num_lanes;k++)
-            segment->unlink_lanes(j,k);
-        }
-        if(restrictions&RESTRICTION_LEFT)
+        segment=(*left_road)->get_segment_by_index(i);
+        for(unsigned int j=0;j<num_lanes;j++)
         {
-          for(unsigned int k=0;k<j;k++)
-            segment->unlink_lanes(j,k);
-        }  
+          restrictions=this->get_parent_way().get_lane_restriction(j+this->get_parent_way().get_num_forward_lanes());
+          if(restrictions&RESTRICTION_RIGHT)
+          {
+            for(unsigned int k=j+1;k<num_lanes;k++)
+              segment->unlink_lanes(j,k);
+          }
+          if(restrictions&RESTRICTION_LEFT)
+          {
+            for(unsigned int k=0;k<j;k++)
+              segment->unlink_lanes(j,k);
+          }  
 //        if(restrictions&RESTRICTION_THROUGH)
 //          segment->unlink_lanes(j,j);
+        }
       }
     }
+    else
+    {
+      delete (*left_road);
+      (*left_road)=NULL;
+    }
   }
   else
     (*left_road)=NULL;