break out parse_chunk() into its own function