      - parameter object: The object to be removed.
      */
     @discardableResult public mutating func remove(object: T)-> T? {
-        guard let index = weakReferecesContainers.index(where: { $0.weakReference === object as AnyObject }) else { return nil }
-        return weakReferecesContainers.remove(at: index).weakReference as? T
+        var result: T?
+        synced(lockObject) {
+            guard let index = weakReferecesContainers.index(where: { $0.weakReference === object as AnyObject }) else { return }
+            result = weakReferecesContainers.remove(at: index).weakReference as? T
+        }
+        
+        return result
     }
     
     /**


import Foundation

public struct LNZWeakCollection<T>: CustomStringConvertible, Sequence, IteratorProtocol {
    private var weakReferecesContainers: [LNZWeakContainer<AnyObject>] = [LNZWeakContainer<AnyObject>]()
    private var currentIndex: Int = 0
    
    ///The count of nonnil objects stored in the array
    public var count: Int { return weakReferences.count }

    
    public mutating func next() -> T? {
        cleanup()
        var result: T?
        synced(lockObject) { 
            guard count > 0 && currentIndex < count else { return }
            let object = weakReferences[currentIndex]
            currentIndex += 1
            result = object
        }
        return result
    }
}
