Update tools.py

clean up code