changing python code to support python 3