                 var iKeyLength: Int = 0
                 levelDBIteratorGetKey(iterator, &iKey, &iKeyLength)
                 #if swift(>=3.0)
-                    if let iKey = iKey {
-                #endif
-                if len > 0 {
+                    if len > 0, let iKey = iKey {
                     let cmp = memcmp(iKey, startingKey.cString, len)
                     if cmp > 0 {
-                        levelDBIteratorMoveBackward(iterator)
-                    }
-                }
-                #if swift(>=3.0)
+                    levelDBIteratorMoveBackward(iterator)
+                    }
+                    }
+                #else
+                    if len > 0 {
+                        let cmp = memcmp(iKey, startingKey.cString, len)
+                        if cmp > 0 {
+                            levelDBIteratorMoveBackward(iterator)
+                        }
                     }
                 #endif
             } else {

            levelDBIteratorGetKey(iterator, &iKey, &iKeyLength);
            #if swift(>=3.0)
                if let iKey = iKey {
            #endif
            if let prefix = prefix {
                if memcmp(iKey, prefix.cString, min(prefix.length, iKeyLength)) != 0 {
                    break
                }
            }
            if let iKeyString = NSString(bytes: iKey, length: iKeyLength, encoding: stringEncoding) as? String {
                #if swift(>=3.0)
                    var iData: UnsafeMutableRawPointer? = nil
                #else
                    var iData: UnsafeMutableRawPointer = nil
                #endif
                var iDataLength: Int = 0
                levelDBIteratorGetValue(iterator, &iData, &iDataLength)
                #if swift(>=3.0)
                    if let iData = iData {
                #endif
                if let v = decoder(iKeyString, NSData(bytes: iData, length: iDataLength)) {
                    if let predicate = predicate {
                        #if swift(>=3.0)
                            if predicate.evaluate(with: v) {
                            block(iKeyString, v, &stop)
                            }
                        #else
                            if predicate.evaluateWithObject(v) {
                                block(iKeyString, v, &stop)
                            }
                        #endif
                    } else {
                        block(iKeyString, v, &stop)
                    }
                }
                #if swift(>=3.0)
                    }
                #endif
            }
            #if swift(>=3.0)
                }
            #endif
            if (stop) {

        var rawDataLength: Int = 0
        let status = levelDBItemGet(db, key.cString, key.length, &rawData, &rawDataLength)
        if status == 0 {
            free(rawData)
            return true
        } else {
            return false
        }
