public function parseData($data, array $modes, $key = null)
    {
        $return = [];

        uksort($modes, function ($a, $b) {
            return substr_count($b, '.')-substr_count($a, '.');
        });

        if (Utility::isCollection($data)) {
            $parsed = $this->parseCollection($modes, $data, $return);
        } else {
            $parsed = $this->parseResource($modes, $data, $return);
        }

        if ($key !== null) {
            $return[$key] = $parsed;
        } else {
            if (in_array('sideload', $modes)) {
                throw new InvalidArgumentException('$key cannot be null when ' .
                                    'resources are transformed using sideload.');
            }

            $return = $parsed;
        }

        return $return;
    }