Refactor main.py to improve Cyclomatic Complexity.