Refactored Main.py code