         return queue
     }()
     // Queue for getting/releasing databases in pool
+    // To prevent weird behaviour from accessing properties from multiple threads
     private lazy var poolQueue: dispatch_queue_t = {
         [unowned self] in
         var queue = dispatch_queue_create("swiftdata.pool.conn.\(self)", DISPATCH_QUEUE_SERIAL)
         return queue
-        }()
+    }()
     
+    // Max number of connections to keep in the connection pool
+    // Note: this only limits the connections in the connPool array
     public var maxSustainedConnections = 5
     
     public init() {

        useWALMode()
    }
    
    public init(path: String?, withFlags flags: SQDatabase.Flags) {
        self.path = path
        self.flags = flags
        useWALMode()
    }
    
    deinit {
        useDeleteMode()
        connPool = []
        inUsePool = [:]
    }
    
    private func useWALMode() {
        let db = SQDatabase(path: path)
        db.openWithFlags(flags)
        db.query("PRAGMA journal_mode=WAL", withObjects: [])
        connPool.append(db)
    }
    
    private func useDeleteMode() {
        let (index, db) = getConnection()
        db.query("PRAGMA journal_mode=DELETE", withObjects: [])
        releaseConnection(index)
    }
    
    private func getConnection() -> (Int, SQDatabase) {
        var index = 0
        var db: SQDatabase?
        dispatch_sync(poolQueue, {
            self.useID++
            index = self.useID
            if self.connPool.isEmpty {
                let database = SQDatabase(path: self.path)
                database.openWithFlags(self.flags)
                self.inUsePool[self.useID] = database
                println("Using new connection: \(self.useID)")
                db = database
                return
            }
            let database = self.connPool.removeLast()
            self.inUsePool[self.useID] = database
            println("Using connection: \(self.useID)")
            db = database
            return
        })
        return (index, db!)
    }
    
    private func releaseConnection(index: Int) {
        dispatch_sync(poolQueue, {
            if self.connPool.count < self.maxSustainedConnections {
                println("Returning connection: \(index)")
                let database = self.inUsePool.removeValueForKey(index)!
                self.connPool.append(database)
                return
            }
            self.inUsePool[index] = nil

        return status
    }
    
    public func transactionAsync(closure: (SQDatabase)->Bool) {
        dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), {let suc = self.transaction(closure)})
    }
    
    public func write(closure: (SQDatabase)->Void) {
        let (index, db) = getConnection()
        dispatch_sync(writeQueue, {
