public function &getTagRef($tag)
    {
        if ($this->isTopTag($tag)) {
            return $this->template;
        }

        $a = explode('#', $tag);
        $tag = array_shift($a);
        //$ref = array_shift($a); // unused
        if (!isset($this->tags[$tag])) {
            throw $this->exception('Tag not found in Template')
                ->addMoreInfo('tag', $tag)
                ->addMoreInfo('tags', implode(', ', array_keys($this->tags)));
        }

        // return first array element only
        reset($this->tags[$tag]);
        $key = key($this->tags[$tag]) !== null ? key($this->tags[$tag]) : null;

        return $this->tags[$tag][$key];
    }