Refactored out functions to utils.py and document them.