some fixes to polyline to_polygon