Refractored and fixed main.py