Added support for python3, while maintaining compatibility with python2