Moved utility code into utils.py from main script.