optimized 'detecting compressed data and decompressing' code