Refactoring of general purpose function into utils.py.