             guard scanner.scanUpTo("}", into: &token) else {
                 continue
             }
-
+            
             if scanner.scanString("}", into: nil) {
-                switch token ?? "" {
-                case "way_name": result += wayName
-                case "destination": result += destination
-                case "exit_number": result += exit
-                case "rotary_name": result += rotaryName
-                case "lane_instruction": result += laneInstruction ?? ""
-                case "modifier": result += modifierConstant
-                case "direction": result += directionFromDegree(degree: bearing)
-                case "nth": result += nthWaypoint // TODO: integrate
-                default: break
+                if let tokenType = TokenType(rawValue: token as! String) {
+                    var replacement: String
+                    switch tokenType {
+                    case .wayName: replacement = wayName
+                    case .destination: replacement = destination
+                    case .exit: replacement = exit
+                    case .rotaryName: replacement = rotaryName
+                    case .laneInstruction: replacement = laneInstruction ?? ""
+                    case .modifier: replacement = modifierConstant
+                    case .direction: replacement = directionFromDegree(degree: bearing)
+                    case .wayPoint: replacement = nthWaypoint
+                    }
+                    if tokenType == .wayName {
+                        result += replacement // already modified above
+                    } else {
+                        result += modifyValueByKey?(tokenType, replacement) ?? replacement
+                    }
                 }
             } else {
                 result += token as! String
             }
+            
         }
 
         // remove excess spaces

    typealias InstructionsByModifier = [String: InstructionsByToken]
    
    override func string(for obj: Any?) -> String? {
        guard let step = obj as? RouteStep else {
            return nil
        }

class OSRMInstructionFormatter: Formatter {
    let version: String
    let instructions: [String: Any]
    
    enum TokenType: String {
        case wayName = "way_name"
        case destination = "destination"
        case rotaryName = "rotary_name"
        case exit = "exit_number"
        case laneInstruction = "lane_instruction"
        case modifier = "modifier"
        case direction = "direction"
        case wayPoint = "way_point"
    }
    
    let ordinalFormatter: NumberFormatter = {
        let formatter = NumberFormatter()
