       if let expander = expander {
         expression = expression.substringFromIndex(expression.startIndex.successor())
       } else {
-        expander = Expander(prefix: "", joiner: ",") { _x, string -> String in
-          if let string = string {
-            return string.percentEncoded()
-          }
-
-          return ""
-        }
+        expander = Expander(prefix: "", joiner: ",", expandPercentEncoded)
       }
 
       return expander.prefix + expander.joiner.join(expression.componentsSeparatedByString(",").map { variable -> String in


        return "\(key)"
      }),
      "&": Expander(prefix: "&", joiner: "&", { (key, string) -> String in
        if let string = string {
          return "\(key)=\(string)"
        }

        return ""
      }),
      "?": Expander(prefix: "?", joiner: "&", { (key, string) -> String in
        if let string = string {
          return "\(key)=\(string)"
        }

        return ""
      }),
      "/": Expander(prefix: "/", joiner: "/", { (key, string) -> String in
        if let string = string {
          return string
        }

        return ""
      }),
    ]

    return regex.substitute(template) { string in

  // Expand template as a URI Template using the given variables
  public func expand(variables:[String:AnyObject]) -> String {
    let operatorHandlers:Dictionary<String, Expander> = [
      "+": Expander(prefix: "", joiner: ",", expandPercentEscaped),
      "#": Expander(prefix: "#", joiner: ",", expandPercentEscaped),
      ".": Expander(prefix: ".", joiner: ".", expandValue),
      ";": Expander(prefix: ";", joiner: ";", { (key, string) -> String in
        if let string = string {
          if countElements(string) > 0 {
