Added support for Python 3 (still works with Python 2).