private function makeResponse($result, $key = null, $cast = null)
    {
        if (array_key_exists('faultCode', $result->toArray()))
            return $result['faultCode'];

        if (!is_null($key) && array_key_exists($key, $result->toArray()))
            $result = $result->get($key);

        if ($cast) settype($result, $cast);

        return $result;
    }