cleanup main.py

no functionality change, just a small code refactor.