refactor main.py, flesh out functions from main function

@stdweird, @wpoely86: please review?

The diff is going to look a bit messy, maybe you want to look at the actual new `main.py` instead...
interesting definition of override, given that it doesn't override when `False`. add a comment to explain what it does/doesn't do and why it should be used (eg in the docstring).