Correctness and performance improvements for Chunk::generate().