Split out chunking logic and added spec.