Python 2 compatibility

Updated script to work in python 2 or python 3