Some changes in tools.py