moving some generic functions to functions.py