Port to Python 3 (and remain compatible with Python 2.7)