             if backward {
                 var i: Int = len - 1
                 //var startingKeyCopy = startingKey
-                let startingKeyPtr = UnsafeMutablePointer<Int8>(malloc(len))
+                let startingKeyPtr = UnsafeMutablePointer<UInt8>(malloc(len))
                 memcpy(startingKeyPtr, startingKey.cString, len)
-                var keyChar: UnsafeMutablePointer<Int8> = startingKeyPtr
+                var keyChar: UnsafeMutablePointer<UInt8> = startingKeyPtr
                 while true {
                     if i < 0 {
                         levelDBIteratorMoveToLast(iterator)

        } else {
            levelDBIteratorMoveToFirst(iterator)
        }
        
    }
    
    func enumerateKeysUsingBlock(_ block: LevelDBKeyBlock) {
        self.enumerateKeysBackward(false, startingAtKey: nil, filteredByPredicate: nil, andPrefix: nil, usingBlock: block)
    }
    
    func enumerateKeysBackward(_ backward: Bool, startingAtKey key: String?, filteredByPredicate predicate: NSPredicate?, andPrefix prefix: String?, usingBlock block: LevelDBKeyBlock) {
        guard let db = db else {
            print("Database reference is not existent (it has probably been closed)")
            return
        }
        let iterator = levelDBIteratorNew(db)
        var stop = false
        var iterate : LevelDBKeyValueBlock
        if let predicate = predicate {
            iterate = {key, value, stop in
                if predicate.evaluateWithObject(value) {
                    block(key, stop)
                }
            }
        } else {
            iterate = {key, value, stop in
                block(key, stop)
            }
        }
        _startIterator(iterator, backward: backward, prefix: prefix, start: key)
        while levelDBIteratorIsValid(iterator) {
            
            let iKey: UnsafeMutablePointer<UnsafeMutablePointer<Int8>> = nil
            let iKeyLength: UnsafeMutablePointer<Int> = nil
            levelDBIteratorGetKey(iterator, iKey, iKeyLength)
            
            if let prefix = prefix {
                if memcmp(iKey, prefix.cString, min(prefix.length, iKeyLength[0])) != 0 {
                    break
                }
            }
            let iKeyString = String(bytes: iKey, length: iKeyLength, encoding: NSUTF8StringEncoding)
            
            let iData: UnsafeMutablePointer<UnsafeMutablePointer<Void>> = nil
            let iDataLength: UnsafeMutablePointer<Int> = nil
            levelDBIteratorGetValue(iterator, iData, iDataLength)
            let v : AnyObject? = (predicate == nil) ? nil : decoder(iKeyString, NSData(bytes: iData[0], length: iDataLength[0]))
            iterate(iKeyString, v!, &stop)
            if stop {
                
            }
            backward ? levelDBIteratorMoveBackward(iterator) : levelDBIteratorMoveForward(iterator)
        }
        levelDBIteratorDelete(iterator)
    }
    
    func enumerateKeysAndObjectsLazily(backward backward: Bool, startingAtKey key: String?, andPrefix prefix: String?, usingBlock block:LevelDBLazyKeyValueBlock) {
        guard let db = db else {
            print("Database reference is not existent (it has probably been closed)")
            return
        }
        var iterator = levelDBIteratorNew(db)
        var stop = false
        var iterate : LevelDBLazyKeyValueBlock
        
        
        /*if let predicate = predicate {
         iterate = {key, valueGetter, stop in
         //key, valueGetter, stop in
         // We need to get the value, whether the `lazily` flag was set or not
         var value = valueGetter()
         // If the predicate yields positive, we call the block
         if predicate.evaluateWithObject(value) {
         if lazily {
         block(key, valueGetter, stop)
         } else {
         block(key, value, stop)
         }
         }
         }
         } else {*/
        //if lazily {
        //block(key, valueGetter, &stop)
        /*}
         else {
         block(key, valueGetter(), &stop)
         }*/
        //}
    }
    
    func deleteDatabaseFromDisk() {
        self.close()
        let fileManager = NSFileManager.defaultManager()
        //var error: NSError?
        do {
            try fileManager.removeItemAtPath(path)
        }
        catch {
        }
    }
    
    func close() {
        if let db = db {
            levelDBDelete(db)
            self.db = nil
        }
    }
    
    func closed() -> Bool {
        /*if let db = db {
            levelDBDelete(db)
            self.db = nil
        }*/
        return db == nil
    }
    
    /*
    func dealloc() {
        self.close()
        //name
        //path
        super.dealloc()
    }*/
    
}

/*

        self.db = levelDBOpen(path.cString)
    }
    
    deinit {
        self.close()
    }
    
    // MARK: - Class methods
    
    class func databaseInLibraryWithName(_ name: String) -> AnyObject {
