Updated for Python3 compatibility