Massive refactoring to simplify main.
Will go with the configs.json format refactoring.