move general functions out to utils.py