refactor code and  add utils.py file containing all utility functions