Make chunk_size configurable and minor cleanups