Minor refactoring, partially document main.py