Fix chunk generation and decoding