Update main.py

Added functions instead of while loop which fixes the issue of some of the variables being reset each time