           startIndex = im!.bodyRange().location
           pat = ip
           ret = im
-          if startIndex == pos {
+          if im!.bodyRange().location == pos {
             break
           }
         }

    var iterations = maxIterations
    for var i = 0; i < sdata.length && iterations > 0; iterations-- {
      var (pat, result) = language.rootPattern.cache(sdata, position: i)
      println(result)
      var newLineLocation = sdata.rangeOfCharacterFromSet(NSCharacterSet.newlineCharacterSet(), options: nil, range: NSRange(location: i, length: sdata.length - i)).location
      if result == nil {
        break

    if cachedPatterns.count == 0 {
      for pattern in patterns {
        cachedPatterns.append(pattern)
      }
    } 
    misses++
