Refactoring the python code in util package