cleaned up chunking code