Fix chunked sending problems pointed out by @blakejohnson