Adding fixes to make script compatible with either python2 or python3