         case InvalidSubscript(path: JSONPath, componentStack: JSONPathComponentsStack)
         case MissingValue(path: JSONPath)
     }
-
-
+    
+    
     //MARK:- Optional value fetching
-
+    
     public func optionalValueAtPath<T>(path: JSONPath, substituteNSNullWithNil: Bool = true) -> T? {
         return optionalValueAtPath(path, substituteNSNullWithNil: substituteNSNullWithNil, errorHandler: { _ in return nil })
     }
-
+    
     
     public func optionalValueAtPath<T>(path: JSONPath, substituteNSNullWithNil: Bool = true, errorHandler: ((JSONPathError) throws -> T?)) rethrows -> T? {
         var untypedValue: Any? = object
         var componentsErrorStack = JSONPathError.JSONPathComponentsStack()
-
+        
         for component in path.components {
             componentsErrorStack.append((component, untypedValue))
-
+            
             switch component {
             case .SelfReference:
                 break
-
+                
             case .Numeric(let number):
                 //Check the collection is valid
                 guard let array = untypedValue as? NSArray else {
                     let error = JSONPathError.UnexpectedType(path: path, componentStack: componentsErrorStack, NSArray.self)
                     return try errorHandler(error)
                 }
-
+                
                 //Check the index is valid
-                guard let index = absoluteIndexForRelativeIndex(Int(number)) else {
+                guard let index = array.absoluteIndexForRelativeIndex(Int(number)) else {
                     //TODO: The erro should be invalidIndex
                     let error = JSONPathError.InvalidSubscript(path: path, componentStack: componentsErrorStack)
                     return try errorHandler(error)
                 }
                 untypedValue = array[index]
-
+                
             case .Text(let key):
                 guard let dict = untypedValue as? NSDictionary else {
                     let error = JSONPathError.UnexpectedType(path: path, componentStack: componentsErrorStack, NSDictionary.self)
                     return try errorHandler(error)
                 }
-
+                
                 //Check the index is valid
                 guard let element = dict[key] else {
                     let error = JSONPathError.InvalidSubscript(path: path, componentStack: componentsErrorStack)

                untypedValue = element
            }
        }

        if untypedValue == nil //This can only occur when the rootObject is nil and the path consists only of .SelfReference
        || (substituteNSNullWithNil && untypedValue is NSNull) {
            return nil
        }

        guard let value = untypedValue as? T else {
            let error = JSONPathError.UnexpectedType(path: path, componentStack: componentsErrorStack, T.self)
            return try errorHandler(error)
        }

        return value
    }


    //MARK: Non-optional value fetching

    public func valueAtPath<T>(path: JSONPath, errorHandler: (JSONPathError) throws -> T) rethrows -> T {
        
        guard let value = try optionalValueAtPath(path, substituteNSNullWithNil: false, errorHandler: { try errorHandler($0) }) else {

//MARK:- JSONPath extension

extension JSONReader {
    
    public enum JSONPathError: ErrorType {
        public typealias JSONPathComponentsStack = [(JSONPath.Component, Any?)]
        case UnexpectedType(path: JSONPath, componentStack: JSONPathComponentsStack, Any.Type)
