Port to support both python2 and python3