Added Python 3.x support by using BytesIO class instead of StringIO.StringIO (which is strictly for Python 2.x)