Refactor main.py