Refactoring to utils.py