                     if keyChar[0] < 255 {
                         keyChar[0] += 1
                         levelDBIteratorSeek(iterator, UnsafeMutablePointer<Int8>(startingKeyPtr), len)
-                        if levelDBIteratorIsValid(iterator) {
+                        if !levelDBIteratorIsValid(iterator) {
                             levelDBIteratorMoveToLast(iterator)
                         }
+                        break
                     }
                     i -= 1
                 }
                 free(startingKeyPtr)
-                if levelDBIteratorIsValid(iterator) {
+                if !levelDBIteratorIsValid(iterator) {
                     return
                 }
-                
                 var iKey: UnsafeMutablePointer<Int8> = nil
                 var iKeyLength: Int = 0
                 levelDBIteratorGetKey(iterator, &iKey, &iKeyLength)

    
    private func _startIterator(_ iterator: UnsafeMutablePointer<Void>, backward: Bool, prefix: String?, start key: String?) {
        var startingKey: String
        //if let prefix = prefix {
        if let prefix = prefix {
            startingKey = prefix
            if let key = key {

            // we need to start on the next key (maybe discarding the first iteration)
            if backward {
                var i: Int = len - 1
                let startingKeyPtr = UnsafeMutablePointer<UInt8>(malloc(len))
                memcpy(startingKeyPtr, startingKey.cString, len)
                var keyChar: UnsafeMutablePointer<UInt8> = startingKeyPtr
