fix some bugs in chunking I/O; add unit tests