A few changes to be compatible with Python 3