Simplify the code and fix a bug where large responses would be truncated.