public function decode($data)
    {
        if ($data[0] == 0x00 && $data[1] == 0x01) {
            throw new Exception('LZW flavour not supported.');
        }

        $this->_initsTable();

        $this->_data = $data;
        $this->_dataLength = strlen($data);

        // Initialize pointers
        $this->_bytePointer = 0;
        $this->_bitPointer = 0;

        $this->_nextData = 0;
        $this->_nextBits = 0;

        $oldCode = 0;

        $unCompData = '';

        while (($code = $this->_getNextCode()) != 257) {
            if ($code == 256) {
                $this->_initsTable();
                $code = $this->_getNextCode();

                if ($code == 257) {
                    break;
                }

                if (!isset($this->_sTable[$code])) {
                    throw new Exception('Error while decompression LZW compressed data.');
                }

                $unCompData .= $this->_sTable[$code];
                $oldCode = $code;

            } else {

                if ($code < $this->_tIdx) {
                    $string = $this->_sTable[$code];
                    $unCompData .= $string;

                    $this->_addStringToTable($this->_sTable[$oldCode], $string[0]);
                    $oldCode = $code;
                } else {
                    $string = $this->_sTable[$oldCode];
                    $string = $string . $string[0];
                    $unCompData .= $string;

                    $this->_addStringToTable($string);
                    $oldCode = $code;
                }
            }
        }

        return $unCompData;
    }