Python 3 compatibility

I made some adjustments to make it to work on Python 3.