added a Python3 implementation