Move all util functions to lib/util.py and create unit test