Fix tools.py for python3