Python3 compatability fixes

I made some changes to make your library compatible with Python3 (as well as Python2, as before).