implementing extract_chunks