cleaned up code in functions.py