bugfix in tools.py