refactoring useful functions into util.py