Convert source code to be able to run both on python2 and python3