Improve compress chunks function