small changes to make compatible with Python 3.1 and 3.2