     
     public mutating func removeValueForKey(key: Key) -> Value? {
         if let index = orderedKeys.indexOf(key) {
+            guard let currentValue = keysToValues[key] else {
+                fatalError("Inconsistency error occured in OrderedDictionary")
+            }
+            
             orderedKeys.removeAtIndex(index)
-            guard let currentValue = keysToValues[key] else { fatalError("Inconsistency error occured in OrderedDictionary.") }
             keysToValues[key] = nil
+            
             return currentValue
         } else {
             return nil

            guard nextIndex < lastIndex else { return nil }
            
            let nextKey = self.orderedKeys[nextIndex]
            guard let nextValue = self.keysToValues[nextKey] else { fatalError("Inconsistency error occured in OrderedDictionary.") }
            let element = (nextKey, nextValue)
            
            nextIndex++

    
    public subscript(index: Index) -> Element {
        get {
            guard let element = elementAtIndex(index) else {
                fatalError("OrderedDictionary index out of range")
            }
            
            return element
        }
        set(newValue) {
            updateElement(newValue, atIndex: index)
