More changes to make it work in Python 3.

Some more changes to the initial code, include some changes to make it
work in Python 3.