                     // save images to local
 
                     request.avatar.saveOriginalImage(image, styledImage: styledImage)
-                }
-            })
+                })
+            }
 
             self.requestPool.removeRequestsWithURL(URL)
         }


import UIKit

func ==(lhs: AvatarPod.Request, rhs: AvatarPod.Request) -> Bool {
    return lhs.key == rhs.key
}

public class AvatarPod {

    static let sharedInstance = AvatarPod()

    private init() {
    }

    let cache = NSCache()



    public typealias Completion = (finished: Bool, image: UIImage, cacheType: CacheType) -> Void

    private struct Request {

        let avatar: Avatar
        let completion: Completion

        var URL: NSURL? {
            return avatar.URL
        }

        var key: String {
            return avatar.key
        }
    }

    private class RequestTank {

        let URL: NSURL
        var requests: [Request] = []

        init(URL: NSURL) {
            self.URL = URL
        }
    }

    private class RequestPool {

        private var requestTanks = [NSURL: RequestTank]()

        func addRequest(request: Request) {

            guard let URL = request.URL else {
                return
            }

            if let requestTank = requestTanks[URL] {
                requestTank.requests.append(request)

            } else {
                let requestTank = RequestTank(URL: URL)
                requestTanks[URL] = requestTank
                requestTank.requests.append(request)
            }
        }

        func requestsWithURL(URL: NSURL) -> [Request] {

            guard let requestTank = requestTanks[URL] else {
                return []
            }

            return requestTank.requests
        }

        func removeRequestsWithURL(URL: NSURL) {

            requestTanks.removeValueForKey(URL)
        }

        func removeAllRequests() {
            requestTanks.removeAll()
        }
    }

    private var requestPool = RequestPool()

    private let requestQueue = dispatch_queue_create("com.nixWork.Navi.requestQueue", DISPATCH_QUEUE_SERIAL)
    private let cacheQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)

    private func completeRequest(request: Request, withStyledImage styledImage: UIImage, cacheType: CacheType) {

