Converted code to run on both Python 2 & 3