Make implementation compatible with python2.6 and python3