Replaced StringIO with BytesIO