Use bytesIO instead of SringIO for python3 compatibility + other python3 compatibility fixes