Add more Python 3 compatibility

Python 2 compatibility is maintained.