Common code to utils.py