Offloaded some functions into tools.py