Added (and tested) full compatibility with both python 2 and python 3