Improve compression with chunked encoding

Based on ideas from @tromer