     
     :returns: Array of match results as MatchObject instances
     */
-    public func finditer(string: String, _ pos: UInt = 0, _ endpos: UInt? = nil) -> [MatchObject] {
+    public func finditer(string: String, _ pos: Int = 0, _ endpos: Int? = nil) -> [MatchObject] {
       guard let regex = regex else {
         return []
       }
-      let start = Int(pos)
-      let end = endpos == nil ? Int(string.characters.count) : Int(endpos!)
+      let start = pos > 0 ?pos :0
+      let end = endpos ?? string.characters.count
       let length = max(0, end - start)
       let range = NSRange(location: start, length: length)
       let options = NSMatchingOptions(rawValue: 0)
       var matches = [NSTextCheckingResult]()
-      regex.enumerateMatchesInString(string, options: options, range: range) {
-        (result: NSTextCheckingResult?, flags: NSMatchingFlags, ptr: UnsafeMutablePointer<ObjCBool>) in
+      regex.enumerateMatchesInString(string, options: options, range: range) { result, _, _ in
         if let result = result {
           matches.append(result)
         }

    
    :returns: search result as MatchObject instance if a match is found, otherwise return nil
    */
    public func search(string: String, _ pos: UInt = 0, _ endpos: UInt? = nil, options: [NSMatchingOptions] = []) -> MatchObject? {
      guard let regex = regex else {
        return nil
      }
      let start = Int(pos)
      let end = endpos == nil ? Int(string.characters.count) : Int(endpos!)
      let length = max(0, end - start)
      let range = NSRange(location: start, length: length)
      let options = NSMatchingOptions(rawValue: options.reduce(0) {$0 | $1.rawValue})

      let maxCount = count == 0 ? Int.max : (count > 0 ? count : 0)
      var n = 0
      var offset = 0
      regex.enumerateMatchesInString(string, options: options, range: range) { result, _, stop in
        if maxCount <= n {
          stop.memory = true
          return
        }
        if let result = result {
