move common functions to util.py