Changing text protocol processing to use BytesIO; Refactoring