public function fetch_friends($gamertag, $region)
    {
        $gamertag  = trim($gamertag);
        $url       = 'https://live.xbox.com/' . $region . '/Friends';
        $key       = $this->version . ':friends.' . $gamertag;
        $data      = $this->__cache->fetch($key);
        $freshness = 'from cache';

        if (!$data) {
            $data      = $this->fetch_url($url);
            $post_data = '__RequestVerificationToken=' . urlencode(trim($this->find($data, '<input name="__RequestVerificationToken" type="hidden" value="', '" />')));
            $headers   = array('X-Requested-With: XMLHttpRequest', 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8');
            $data      = $this->fetch_url('https://live.xbox.com/' . $region . '/Friends/List?Gamertag=' . urlencode($gamertag), $url, 10, $post_data, $headers);
            $freshness = 'new';
            $this->__cache->store($key, $data, 3600);
        }

        $json = json_decode($data, true);

        if (!empty($json['Data']) && $json['Data']['Friends'] != null) {
            $friends                 = array();
            $friends['total']        = 0;
            $friends['totalonline']  = 0;
            $friends['totaloffline'] = 0;

            $i = 0;
            foreach ($json['Data']['Friends'] as $friend) {
                $friends['friends'][$i]['gamertag']          = $friend['GamerTag'];
                $friends['friends'][$i]['gamerpic']['small'] = $friend['GamerTileUrl'];
                $friends['friends'][$i]['gamerpic']['large'] = $friend['LargeGamerTileUrl'];
                $friends['friends'][$i]['gamerscore']        = $friend['GamerScore'];
                $friends['friends'][$i]['online']            = (bool)$friend['IsOnline'];
                $friends['friends'][$i]['status']            = $friend['Presence'];
                $friends['friends'][$i]['lastseen']          = (int)substr($friend['LastSeen'], 6, 10);

                $friends['total']++;
                if ($friend['IsOnline']) {
                    $friends['totalonline']++;
                } else {
                    $friends['totaloffline']++;
                }

                $i++;
            }

            $friends['freshness'] = $freshness;
            return $friends;
        } else {
            $this->error = 503;
            $this->__cache->remove($key);
            $this->force_new_login();
            return false;
        }
    }