fixing code to suport python 3

This code fixes syntax errors that break compatibility with Python 3.