Added code to make compression more memory-efficient.