Fixed c code to support chunking