Refactor and use helper functions from helper.py