added error checking for chunking