fix chunking bug

This fixes a chunking bug identified by @jakebolewski in #178 (and includes a regression test).