Move common functions to utils.py