changed code to be compliant with newer versions of python