         if let travel = travel{
             for aTrip in travel.trips {
                 if aTrip.date == trip.date {
+                    if trip.locations.count > aTrip.locations.count {
+                        aTrip.locations = trip.locations
+                    }
+                    for (key, value) in trip.extraData{
+                        aTrip.extraData[key] = value
+                    }
                     haveSameTrip = true
                     break
                 }

        travel.distance = distance
        travel.duration = duration
        travel.maxSpeed = Float(maxSpeed)
        cache(travel: travel, vehicleId: vehicleId)
        autoSave()
    }
    
    public func cache(address: Address) {

                    autoSave()
                }
                break
            }
        }
    }
    
    ///Clear travel cache for specified date ranges
    public func clearTripCache(vehicleId: String, date: Date, toDate: Date) {
        var dataChanged = false
        let classname = NSStringFromClass(Travel.self)
        
        var travelDicto: [[String: Any]]!
        if let array = data[classname] as? [[String: Any]]{
            for (userIndex, dicto) in travelDicto.enumerated() {
                if let theVehicleId = dicto["id"] as? String, vehicleId == theVehicleId, var travels = dicto["data"] as? [Travel]{
                    var indexset = IndexSet()
                    var startIndex : Int!
                    var endIndex : Int!
                    var dataChanged = false
                    
                    for (index, theTravel) in travels.enumerated() {
                        var indexesNeedClear = [Int]()
                        for (tripIndex, trip) in theTravel.trips.enumerated(){
                            if trip.date.timeIntervalSince(date) >= 0, trip.date.timeIntervalSince(toDate) < 0{
                                indexesNeedClear.append(tripIndex)
                                dataChanged = true
                            }
                        }
                        if indexesNeedClear.count == 1{
                            theTravel.trips.remove(at: indexesNeedClear.first!)
                        }else if indexesNeedClear.count > 1, let first = indexesNeedClear.first, let last = indexesNeedClear.last{
                            theTravel.trips.removeSubrange(first...last)
                        }
                    }
                    if dataChanged {
                        travelDicto[userIndex]["data"] = travels
                        data[classname] = travelDicto
                        autoSave()
                    }
                    break
                }
            }
        }
    }
