     }
 
     var subenums: [[String: AnyObject]] = []
-    var nextLevelKeyPaths: [[String]] = entries.filter { $0.keyStructure.count > keyPath.count+1 }.map { Array($0.keyStructure.prefix(keyPath.count+1)) }
+    let nextLevelKeyPaths: [[String]] = entries
+      .filter({ $0.keyStructure.count > keyPath.count+1 })
+      .map({ Array($0.keyStructure.prefix(keyPath.count+1)) })
 
     // make key paths unique
-    nextLevelKeyPaths = Array(Set(nextLevelKeyPaths.map { keyPath in
-        keyPath.map { $0.capitalizedString.stringByReplacingOccurrencesOfString("-", withString: "_") }.joinWithSeparator(".")
-    })).sort().map { $0.componentsSeparatedByString(".") }
-
-    for nextLevelKeyPath in nextLevelKeyPaths {
-      let entriesInKeyPath = entries.filter { Array($0.keyStructure.map(normalize).prefix(nextLevelKeyPath.count)) == nextLevelKeyPath.map(normalize) }
+    let uniqueNextLevelKeyPaths = Array(Set(
+      nextLevelKeyPaths.map { keyPath in
+        keyPath.map({
+          $0.capitalizedString.stringByReplacingOccurrencesOfString("-", withString: "_")
+        }).joinWithSeparator(".")
+      }))
+      .sort()
+      .map { $0.componentsSeparatedByString(".") }
+
+    for nextLevelKeyPath in uniqueNextLevelKeyPaths {
+      let entriesInKeyPath = entries.filter {
+        Array($0.keyStructure.map(normalize).prefix(nextLevelKeyPath.count)) == nextLevelKeyPath.map(normalize)
+      }
       subenums.append(structure(entriesInKeyPath, keyPath: nextLevelKeyPath, mapper: mapper))
     }
 

    return components.map { $0.capitalizedString }.joinWithSeparator("")
  }

  private func structure(entries: [Entry], keyPath: [String] = [], mapper: (Entry, [String]) -> [String: AnyObject]) -> [String: AnyObject] {

    var structuredStrings: [String: AnyObject] = [:]

    let strings = entries.filter { $0.keyStructure.count == keyPath.count+1 }.map { mapper($0, keyPath) }
    if !strings.isEmpty {
      structuredStrings["strings"] = strings
    }

    let strings = entries.map { entryToStringMapper($0, []) }
    let structuredStrings = structure(entries, mapper: entryToStringMapper)

    return Context(dictionary:
      [
        "enumName": enumName,
        "tableName": tableName,
        "strings": strings,
        "structuredStrings": structuredStrings
      ]
    )
  }

  private func normalize(string: String) -> String {
