Move functionality to a util.py, fix sys.argv use